使用几个参数angularjs获取元素计数

使用几个参数angularjs获取元素计数,angularjs,angularjs-filter,Angularjs,Angularjs Filter,我想使用angular的过滤器过滤元素,检查2个属性,然后获取返回元素的数量 这就是我尝试过的: $scope.countPriorityActive = true; $scope.getCountActive = function(strCat) { return filterFilterActive($scope.tasks, {priority: strCat, active: true}).length; }; 但它不起作用 我已开始编辑此示例: 我的错误是什么?您忘记在数组的

我想使用angular的过滤器过滤元素,检查2个属性,然后获取返回元素的数量

这就是我尝试过的:

$scope.countPriorityActive = true;
$scope.getCountActive = function(strCat) {
    return filterFilterActive($scope.tasks, {priority: strCat, active: true}).length;
};
但它不起作用
我已开始编辑此示例:
我的错误是什么?

您忘记在数组的元素中添加“active”属性

{
  id: 1,
  name: 'Iron Man',
  fname: 'Tony',
  lname: 'Stark',
  location: 'Stark Tower',
  comic: 'Marvel'
  active: true //this is what you need to add to each element
},

此外,您需要调用“filterFilter”,而不是“filterFilterActive”,除非您自己制作了一个新的过滤器

filterFilterActive的作用是什么?@valepu它应该返回元素长度它在plunkr中工作。如果我添加console.log(filterFilter($scope.heroes,{comic:strCat}).length);对于getCount函数,我可以看到返回的结果。在plunkr里写着“filterFilter”though@valepu,我尝试在值计数中再添加1个值,但有2个值它不起作用没有漫画在plunkr的列表中有“active”属性。如果我在漫画上加上“active:true”,它会正确地计算它