0
我有一個ngRepeat
指令,它根據過濾器的輸出進行計數。除了當我更改動態過濾器的值時,它的功能與預期相同。當我更改過濾器值時,ngRepeat
正確過濾,但計數並不總是隨之更新。他們有時但不是每次都這樣做。我如何確保每次更新價值?AngularJS指令,當範圍變化時進行計算
ngRepeat
<li class="list-group-item" data-ng-repeat="e1 in events | availFilter:filterBy | unique:team" ng-init="teamCount = (events | availFilter:filterBy | filter:{team:e1.team})">
<div class="list-group-item-header" data-ng-click="headerClick($event)" >
<span class="title">{{ e1.team }}</span>
<span class="badge">{{ teamCount.length }}</span>'
</div>
是改變濾光器控制
<li role="presentation" data-ng-class="{ active: activeTab('today') }">
<a data-ng-click="filterBy = 'today';">Today</a>
</li>
<li role="presentation" data-ng-class="{ active: activeTab('before8') }"><a data-ng-click="filterBy = 'before8';">Before 8am</a></li>
<li role="presentation" data-ng-class="{ active: activeTab('after5') }"><a data-ng-click="filterBy = 'after5';">After 5pm</a></li>
過濾
availApp.filter('availFilter', function() {
return function (collection, term) {
var outCollection = [];
switch(term){
case 'today':
outCollection = collection;
break;
case 'before8':
angular.forEach(collection, function(item){
if(item.start.getHours() < 8)
outCollection.push(item);
});
break;
case 'after5':
angular.forEach(collection, function(item){
var hr = item.end.getHours();
var min = item.end.getMinutes();
if(hr > 17 || (hr == 17 && min > 0))
outCollection.push(item);
});
break;
default:
break;
}
return outCollection;
};
});
'filterBy'變量是範圍的一部分,所以我運行的假設是改變它會提醒變化的角度......我想這是BC我用1ngInit'聲明每個行的新變量'這不是範圍 – ExceptionLimeCat 2014-12-03 22:54:31
我最終創建了列表中的數據子集,然後將其附加到您建議的範圍。謝謝。 – ExceptionLimeCat 2014-12-03 23:37:51