1
如何過濾$ location.search()參數上的結果集?
<div ng-repeat="tag in tags">
<div ng-class="{active:tagged(tag.id)}" ng-click="filter(tag.id)">
{{album.title}}
</div>
</div>
如果標記的結果爲true,則附加類active
。
filter('tagged', function() {
return function (id) {
//Assume "tags" is also the name of the parameter.
//"tags" is being set by $location.search({tags:['123','456','789']});
return ($location.search().tags.indexOf(id) != -1)?true:false;
};
});
內ng-class
的約定是錯誤的,但我使用的是作爲一個例子來說明知識差距。
+1此。真正的測試是如果URL參數的狀態發生變化,bool控制類會相應更新。答案是肯定的:http://plnkr.co/edit/s4RNrl?p=preview –