P
P
Peter2016-03-07 12:20:33
Angular
Peter, 2016-03-07 12:20:33

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>

How to find out how much data is left after filtering?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Arthur, 2016-03-07
@volkov_p_v

{{ (data | filter:filter).length }}

S
Sergey, 2016-03-07
Protko @Fesor

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.

J
JIakki, 2016-03-07
@JIakki

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>

something like this

A
Andrew, 2016-03-09
@P1RATE

<li data-ng-repeat="item in list | filter:search as filteredData">
{{filteredData.length}}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question