How do you get the length/number of items returned by a filter predictate in AngularJS?
As a matter of facts, this will work with display filter(orderBy
, limitTo
)
item in list = ( item_array|filter:some_str) | orderBy: pref | limitTo: nItemToDisplay
if you need to display 5 items at a time, you still can use list.length. Usefull for pagination or in datatable.
I managed to find a great answer on the AngularJS Google Group, thanks to Pawel Kozlowski.
ng-repeat="item in filtered = (items | filter:filterExpr)"
Would create the filtered
list on the fly, you can use filtered.length
anywhere else in the current scope to show the count.
i also had to display the length of a filtered array and this one worked for me:
{{ (items | filter:filterExpr).length }}
Try this :
HTML
<span ng-bind="nb"></span>
Javascript
$scope.nb = $filter('filter')(items, filterExpr).length;
In HTML Template Binding
{{ filter_expression | filter : array : expression : comparator}}
In JavaScript
$filter('filter')(array, expression, comparator)