2014-09-20 61 views
1

我試圖讓每個iteration.my代碼項目的總人數是這個我如何獲得項目總的NG-重複

<ul class="phones"> 
     <li ng-repeat="phone in phones | filter:query | orderBy:orderProp" 
     ng-init="index()"  class="thumbnail"> 
     <a href="#/phones/{{phone.id}}" class="thumb"> 
      <img ng-src="{{phone.imageUrl}}"> 
     </a> 
      <a href="#/phones/{{phone.id}}">{{phone.name}}</a> 
     <p>{{phone.snippet}}</p> 
     </li> 
    </ul> 
    <div> 
    {{ total }} 
</div> 

控制器

phonecatApp.controller('PhoneListCtrl', function($scope, $http) 
{ 
$scope.total =0; 
$scope.index =function() 
{ 
    $scope.total ++; 
} 
} 

回答

3

通過動態你的意思是應用過濾器後,手機總沒有當前顯示。

<ul class="phones"> 
    <li ng-repeat="phone in filtered = (phones | filter:query | orderBy:orderProp)" 
    ng-init="index()"  class="thumbnail"> 
    <a href="#/phones/{{phone.id}}" class="thumb"> 
     <img ng-src="{{phone.imageUrl}}"> 
    </a> 
     <a href="#/phones/{{phone.id}}">{{phone.name}}</a> 
    <p>{{phone.snippet}}</p> 
    </li> 
</ul> 
<div> 
{{ filtered.length }} 
</div> 

爲了使更多的數據的意義(獎金提示:))

<div ng-show="query"> 
    <ng-pluralize count="filtered.length" when="{'0': ' No search result ', 'one': ' 1 search result ', 'other': ' {} search results '}"></ng-pluralize> for {{query}} 
</div> 
1

你是不是想獲得手機總數? 你可以簡單地使用length屬性的表達,而不是{{ total }}

{{ phones.length }} 
+0

不完全是,我想的時候NG-重複重複了「總」(值),動態的數量。 – 2014-09-20 20:44:56