Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HEllo frnds,

I am facing issue with get Json array value in @scope.
please check below code.
I want store meta_description value in $scope.
SQL
description 

please give me suggestion. how I can achieve this.

JavaScript
function postCtrl($scope, $http, $routeParams) {
    $http.get('post.php?id=' + $routeParams.postId).success(function(data) {
        $scope.post = data;
    });

    $scope.description = $scope.post.meta_description;  /*I can't access this value*/
}


What I have tried:

function postCtrl($scope, $http, $routeParams) {
$http.get('post.php?id=' + $routeParams.postId).success(function(data) {
$scope.post = data;
});

$scope.description = $scope.post.meta_description;
Posted
Updated 20-May-16 2:52am

1 solution

try this

JavaScript
function postCtrl($scope, $http, $routeParams) {

           $http.get('post.php?id=' + $routeParams.postId).success(function (data) {
               $scope.post = data.data;
               $scope.description = data.data.meta_description;   
           });
       }


the response from the $http will be in data property, so you have use data.data, since you are using the response variable as data

dont try to read the values outside the success event, since it will work independent of the flow of code execution..
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900