我在ng-repeat中有自定义过滤器。 我需要找出返回数组的长度。怎么做? 这是html:
<div ng-repeat="item in vm.work_items | itemsInFolder: search">
<div>item.name</div>
</div>
<div>{{returnedArray.length}}</div> //I need set returned value here.
过滤器:
.filter('itemsInFolder', function($window, NamesService) {
return function (items, input) {
if(!input) {
return items;
} else {
var out = [];
items.forEach(function(item){
//here goes some custom logic, which returns array;
out.push(item);
}
return out;
}
});
答案 0 :(得分:0)
Angular 1.3中的新功能,您可以使用ng-repeat
选项扩展as
指令。
<div ng-repeat="item in vm.work_items | itemsInFolder: search as results">
<div>item.name</div>
</div>
<p>{{results.length}}</p>