Answer the question
In order to leave comments, you need to log in
Is it possible to know the number of elements after filtering in Angularjs?
For filtering I do in view.
<ul>
<li data-ng-repeat="item in list | filter:search>
<span>{{item.name}}</span>
</li>
</ul>
Answer the question
In order to leave comments, you need to log in
don't use collection filtering in templates, prepare data in controller. This feature is only suitable for prototypes, it is better not to do this in production. Filters should return strings and be as fast as possible. Again, you can inject filters into the controller (filterFilter in your case)
. And if you have a filtered collection in the controller, then displaying its length is not a problem at all.
angular.module('app', [])
.controller('aCtrl', function() {
this.count = 0;
})
<ul ng-controller='aCtrl as ctrl' >
<li data-ng-repeat="item in [23,4,5,6,7] | filter:search">
<span ng-init='ctrl.count = ctrl.count + 1'>{{item.name}}</span>
</li>
</ul>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question