javascript - Access Nested JSON objects and their attributes Angularjs -


i new bie angular , trying learn it. trying display user data webservice received response. here's response

    {     "users": {         "searchterm": "angularjs ra1",         "resultsperpage": "20",         "recordstartnumber": "0",         "totalestimatedresults": "6",         "user": [{             "wwid": "123456",             "email": "mary.p.wilson@yahoo.com",             "businesstitle": "project manager",             "name": "mary wilson",             "firstname": "mary",             "lastname": "wilson",             "idsid": "rap"         }, {             "wwid": "1234567",             "email": "steve.r.smith@gmail.com",             "businesstitle": "quality assurance",             "name": "steve smith",             "firstname": "steve",             "lastname": "smith",             "idsid": "drpresto"         }, {             "wwid": "12345678",             "email": "jon.jones@gmail.com",             "businesstitle": "chef",             "name": "jon jones",             "firstname": "jon",             "lastname": "jones",             "idsid": "jjones"         }]     } } 

myscript.js

    var application = angular.module('testmodule', []); application.controller('testcontroller', function ($scope,$http) {     $scope.testvalue = "hello world controller";     $scope.myfunc = function asdf() {         $http.get('http://unifiedcollaborationprofile.gots.com/search/expert/data/v2/?apikey=secret&listfrompersonnumber=0&numpeopleperpage=20&query=angularjs+ra1&returnfriendlyresults=true').then(             function (response) {                 $scope.users = [];                 angular.foreach(response.users, function (value, key) {                     $scope.users.push(value);                 });             });     }; }); 

page.html

<!doctype html> <html ng-app="testmodule"> <head>     <title></title>     <meta charset="utf-8" /> </head> {{2+3}} <body>     <div ng-controller="testcontroller">         {{2+3}}         {{testvalue}}         <input type="text" ng-model="testvalue" />         <input type="button" value="click me users!!!!" ng-click="myfunc()" />         <ul ng-repeat="k in users">             <li>wwid:{{k.wwid}}  email:{{k.email}}  name:{{k.name}}  idsid:{{k.idsid}}</li>         </ul>      </div> </body> </html> <script src="scripts/angular.min.js"></script> <script src="scripts/myscripts/myscript.js"></script> 

but nothing gets rendered on page. not sure if rightly accessing nested user object in users collection of json , properties. missing.

i've created plunker code , did make work change this:

$scope.myfunc = function asdf() {     $http.get('test.json').then(function(response) {       $scope.users = [];       angular.foreach(response.data.users.user, function(value, key) {         $scope.users.push(value);       });     });   }; 

http://plnkr.co/edit/fu1tcnhxsn9dgbxttj9r?p=preview

you must remember then after http promise gets resolved receives object contains several values: status code, headers , data contain data


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -