2016-07-11 2 views
0

ng-repeat를 사용하여 서비스에서받은 객체의 특정 요소를 표시하려고합니다. {{account}}을 사용하면 모든 요소를 ​​렌더링하지만 예를 들어 {{account.idType}}을 시도하면 아무 것도 표시되지 않습니다. 무슨 일이야? 여기 내 HTMLng-repeat는 객체를 표시하지만 객체는 표시하지 않습니다.

<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> 

이며,이 컨트롤러입니다 : $resource가 비동기

{"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

에 의해 $scope.accounts = Account.get()를 교체 당신은 엔드 포인트에서 응답 객체를 게재 할 수 있습니까? 반환 된 것을 보지 않고도 문제를 해결하기가 어렵습니다. – user2263572

답변

1

때문에 (그것은을 반환

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(); 
    }]); 

나는 서비스에서 얻을 응답이있다 약속).

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

이것은 나를 위해 작동하지 않는 것 같습니다. Account.get()이 함수가 아니라는 오류가 발생합니다. 어쩌면 다른 구문이 필요할까요? – natalw

+0

죄송합니다. 원래 코드 인 ng-repeat = "account in accounts"를 다음과 같이 바꾸십시오 : ng-repeat = "account in accounts.linklist" – adkirvien

관련 문제