0

I have an ng-repeat like so:

item in items | filter:myFilter | page:currentPage

I'd like to know the current number of items that filter:myFilter results in for pagination. However, this answer will result in both filters being applied (and the pagination will think there's only one page of results).

How can I conditionally apply filters to a variable created in an ng-repeat?

Community
  • 1
  • 1
SomeKittens
  • 38,868
  • 19
  • 114
  • 143

1 Answers1

1

It's entirely possible to only include some filters in your parenthesis. In the above case, you can do something like:

item in filteredItems = (items | filter:myFilter) | page:currentPage

The result of items | filter:myFilter will be assigned to filteredItems, which is then further filtered by page:currentPage.

The one thing to watch out for is that filteredItems will be set on the parent scope of the one created by ng-repeat and so you'll need to be aware of collisions.

SomeKittens
  • 38,868
  • 19
  • 114
  • 143