Angularjs $resource not working with an array returned from a REST API

前端 未结 6 2148
失恋的感觉
失恋的感觉 2020-12-06 05:15

I am trying to learn angularjs, and have hit a block in trying to databind to an array returned from a Rest API. I have a simple azure api returning an array of person objec

6条回答
  •  不思量自难忘°
    2020-12-06 06:09

    The array you get back from the server isn't a clean array, but has some extra properties. That makes ng-repeat not show anything when you iterate over it using in.

    You need a special iterator to go over the array from the server, which will ignore those extra properties. So extract the array data through forEach first, like this:

    $scope.items = []
    var response = $scope.svc.get();
    angular.forEach(response, function(item) {
      $scope.items.push(item);
    });
    

    Then you can do

    
    

提交回复
热议问题