Can't select json and view it in angular unless i edit json

I want to access json in the same format:

 {"employees":[
{"firstName":"John", "lastName":"Doe"}, 
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
 ]}

      

script:

    phonecatApp.controller('PhoneListCtrl', ['$scope', '$http', function($scope, $http) {
    $http.get('employees/employees.json').success(function(data) {
     $scope.resources = data;
       });

      

if i remove "employees" so its attributes inside [] will get my data. but if left as an example above, I cannot reach my data.

Any help is appreciated.

+3


source to share


1 answer


You just need to follow the JSON structure. Since the data is the entire JSON string, then the employee array is accessible via the employee key. Try the following:



   $scope.resources = data.employees;

      

+2


source







All Articles