ng-repeat显示对象但不显示对象的元素

时间:2016-07-11 14:19:27

标签: angularjs ng-repeat

我想显示使用ng-repeat从服务中收到的对象中的特定元素。当我使用{{account}}时,它会渲染所有元素,但是当我尝试例如{{account.idType}}时,它什么也没有显示。发生了什么事? 这是我的HTML

    <table>
        <thead>
        <tr>
            <th>List of Accounts</th>
        </tr>
        </thead>
        <tbody ng-repeat="account in accounts"  ng-if="account.idType != 0">
          <tr>
            <td>{{account.idType}}</td>
            <td>{{account.linkRel}}</td>
            <td>{{account.linkURI}}</td>
            <td><input type="button" ng-click="editAccount(account.idType)" value="edit"></td>
         </div>

这是控制器:

rest.controller('accountListCtrl',['$scope','$resource','$location','$parse','$routeParams',
    function($scope,$resource, $location, $parse,$routeParams)
    {   
      var Account = $resource('http://localhost\\:8085/WSAT/account/');
       $scope.accounts = Account.get();
    }]);

我从服务中得到的回应是:

{"linklist":[{"idType":"0","linkRel":"Get all accounts","linkType":"Sibling","linkURI":"http://localhost:8085/WSAT/account","linkVerb":"GET"},{"idType":"0","linkRel":"Create a new account","linkType":"Sibling","linkURI":"http://localhost:8085/WSAT/account","linkVerb":"POST"},{"idType":"7","linkRel":"try","linkType":"Child","linkURI":"http://localhost:8085/WSAT/account/7","linkVerb":"GET"},{"idType":"9","linkRel":"try234","linkType":"Child","linkURI":"http://localhost:8085/WSAT/account/9","linkVerb":"GET"}]}

1 个答案:

答案 0 :(得分:1)

因为$resource是异步的(它返回一个promise)。 将$scope.accounts = Account.get()替换为

Account.get().then(function(data){
 $scope.accounts=data.result;
});