Search code examples
javascriptangularjsangularjs-filterangularjs-limitto

Using aliases with multiple filters


I have this code:

<tr ng-repeat="person in ctrl.persons
            | filter : { name: filterName, email: filterEmail} as filtered">

Number of persons filtered by mail and name: {{filtered.length}}

Now I add another filter:

<tr ng-repeat="person in ctrl.persons
                    | filter : { name: filterName, email: filterEmail} 
                    | limitTo : ctrl.size as filtered">

Number of persons filtered by mail and name: {{filtered.length}}

My problem is that the number of persons filtered by mail and name is wrong now, because it's limited to size. What's the best workaround to solve this?

Thanks!


Solution

  • I solved this by using brackets:

    <tr ng-repeat="person in filteredPersons = (ctrl.persons
                            | filter : { name: filterName, email: filterEmail})
                            | limitTo : ctrl.size as filtered">
    
    Number of persons filtered by mail and name: {{filteredPersons.length}}