1

I am new to angular js . I have a json response which i want to convert to list of objects and use ng-repeat to display these object. I am getting a list of these objects which are as follow

    1 : 
{"_id":"56e75b42c9cbbb7765414cdf",
"email":"[email protected]",
"phone":"02-653-2900",
"display_name":"KFC",
"registered_name":"KFC",
"__v":0,
"address":
    {"country":"TH",
       "state":"TH14,
       "postcode":"10150",
       "suburb":"Klongteay",
       "address2":"Sukhumvit Rd",
       "address1":"142 Two Pacific Place"},
"date_modified":"2016-03-15T00:45:54.631Z",
"date_created":"2016-03-15T00:45:54.626Z",
"status":"active",
"logo":{"path_to_file":"90cf845d95.png"}
}

I have saved the above object in $scope.results and i want to do something like

<div ng-repeat="user in  results.data  ">
           <span>Phone </span><span>{{user.phone}}:</span> 
            <span>Display Name</span><span>{{user.display_name}}:</span> 
</div>

How can i achieve this?

3

2 Answers 2

0

Create a new controller

angular.module('appname').controller('ctrl', function($scope, $http){
 $http.get('url-to-json').then(function(res){
  $scope.results = res;
 });
})
Sign up to request clarification or add additional context in comments.

Comments

0

Nothing is wrong with your ng-repeat but the JSON is not valid. A small double quote is missing in "state":"TH14,

Here is the working plunker http://plnkr.co/edit/Z4n9oSIznVnFsNTOcLJX?p=preview

It should be

    1 : 
{"_id":"56e75b42c9cbbb7765414cdf",
"email":"[email protected]",
"phone":"02-653-2900",
"display_name":"KFC",
"registered_name":"KFC",
"__v":0,
"address":
    {"country":"TH",
       "state":"TH14",
       "postcode":"10150",
       "suburb":"Klongteay",
       "address2":"Sukhumvit Rd",
       "address1":"142 Two Pacific Place"},
"date_modified":"2016-03-15T00:45:54.631Z",
"date_created":"2016-03-15T00:45:54.626Z",
"status":"active",
"logo":{"path_to_file":"90cf845d95.png"}
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.