2

I have an ng-repeat with multiple filters like below:

Active Items Found: {{totalActiveItems}}
<div ng-repeat="item in items | filter:searchFilter | filter:{active:true}">
    {{item.title}}
</div>

I'm trying to store the total count outside of the ng-repeat in the totalActiveItems variable.

I saw this answer: How to display length of filtered ng-repeat data

But it doesn't seem to show how to do it for multiple filters.

Sangwin Gawande
  • 7,658
  • 8
  • 48
  • 66
Jordash
  • 2,926
  • 8
  • 38
  • 77

2 Answers2

1

Store the data in a temporary variable in view and display the length using an expression .

Active Items length: {{totalItems.length}}
<div ng-repeat="item in totalItems=(items | filter:searchFilter | filter:{active:true})">
    {{item.title}}
</div>
Robert Ravikumar
  • 912
  • 2
  • 11
  • 29
1

Aliasing the array resulting in the filter works fine even if you're using multiple filters :

Active Items Found: {{items.length}}
<div ng-repeat="item in items | filter:searchFilter | filter:{active:true} as filtered">
    {{item.title}}
</div>
Items found after filtering : {{filtered.length}}
Guillaume Georges
  • 3,878
  • 3
  • 14
  • 32