AngularJS conflit with limitTo and filter in ngrepeat

I have ng-repeat

with a lot of keywords (> 100,000), so I use limitTo:

, but I would like to be able to search in ALL.

Search: <input ng-model="filter:queryKeywords" type="text" placeholder="Filter" autofocus>

<label ng-repeat="k in keywords | limitTo:totalDisplayed | orderBy | filter:queryKeywords">
   {{k}}
</label> 

<!-- Will load 100+ keywords -->
<button class="btn btn-primary" ng-click="seeMore()">See More</button>

      

The problem is my search only works for the items I see.

I would like to search in all elements (even one that I cannot display).

Thank!

+3


source to share


2 answers


You have to change the order of the filters so that the search is first (and therefore applies to all data) and then constrained / ordered:



ng-repeat="k in keywords | 
           filter:queryKeywords |
           limitTo:totalDisplayed |
           orderBy"

      

+9


source


Angular applies filters in order. Changing the order of the filters should fix your problem.

<label ng-repeat="k in keywords | filter:queryKeywords | limitTo:totalDisplayed | orderBy">

      



This means: the first filter, then limit the results to totalDisplayed

and finally order it.

+4


source







All Articles