ng-repeat 显示对象但不显示对象的元素
ng-repeat shows objects but not elements of objects
我想显示我从使用 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"}]}
因为 $resource
是异步的(它 returns 是一个承诺)。
将 $scope.accounts = Account.get()
替换为
Account.get().then(function(data){
$scope.accounts=data.result;
});
我想显示我从使用 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"}]}
因为 $resource
是异步的(它 returns 是一个承诺)。
将 $scope.accounts = Account.get()
替换为
Account.get().then(function(data){
$scope.accounts=data.result;
});