Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS ng-repeat alias expression between multiple filters

According to Angular ngRepeat documentation, you can use the alias expression only at the end of ngRepeat:

Please note that `as [variable name] is not an operator but rather a part of ngRepeat micro-syntax so it can be used only at the end (and not as operator, inside an expression).

In my ng-repeat, I need to filter out items based on property, and then use limitTo filter for pagination purposes.

How can I get number of filtered items before the second filter?

This doesnt ofcourse work:

item in c.items | filter: c.contextFilter as filteredItems | limitTo: c.pagination.pageSize : c.pagination.currentPage*c.pagination.pageSize

Is there any other way I can get the filteredItems.length value ?

like image 288
BlueBallPanda Avatar asked Dec 04 '25 07:12

BlueBallPanda


1 Answers

I had the same problem, I fixed it assigning the result of the first part of the filter expression into a new variable. In your example:

    item in filteredItems = (c.items | filter: c.contextFilter) | limitTo: c.pagination.pageSize : c.pagination.currentPage*c.pagination.pageSize```

<div>{{filteredItems.length}}</div>

Full example with controllerAs syntax:

   item in $ctrl.filteredItems = ($ctrl.items | filter: $ctrl.customFilter | 
   orderBy: $ctrl.order) | limitTo: $ctrl.pagination.pageSize : 
   $ctrl.pagination.currentPage*$ctrl.pagination.pageSize`
like image 135
Matias Fernandez Martinez Avatar answered Dec 05 '25 21:12

Matias Fernandez Martinez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!