2016-07-11 12 views
0

Ich möchte bestimmte Elemente von Objekten anzeigen, die ich von einem Dienst mit ng-repeat empfangen habe. Wenn ich {{account}} verwende, rendert es alle Elemente, aber wenn ich zum Beispiel {{account.idType}} versuche, zeigt es nichts. Was ist los? Hier ist mein HTMLng-repeat zeigt Objekte, aber keine Elemente von Objekten an

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

und dies ist der Controller:

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

die Antwort, die ich aus dem Dienst erhalten, ist dies:

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

Können Sie zeigen Sie Ihre Response-Objekt von dem Endpunkt? Schwer zu beheben, ohne zu sehen, was zurückkommt. – user2263572

Antwort

1

Da $resource asynchron ist (es gibt eine versprechen). $scope.accounts = Account.get() ersetzen

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

das scheint nicht für mich zu funktionieren. Ich bekomme einen Fehler, dass Account.get() keine Funktion ist. Vielleicht braucht es eine andere Syntax? – natalw

+0

Entschuldigung, ersetzen Sie nur in Ihrem ursprünglichen Code ng-repeat = "Konto in Konten" von: ng-repeat = "Konto in accounts.linklist" – adkirvien