3

I have a data array which contains objects (JSON format).

var users = {
  'New':{
    {Name:'One'},
    {Name:'Two'}
  },
  'Old':{
    {Name:'Three'},
    {Name:'Four'}
  }

And i use this construction to display data:

<div ng-repeat="(key, value) in users">
  <p>{{key}}</p>
  <div ng-repeat="user in value | filter: query">
  </div>
</div>

How do I get the count of filtered data? Thanks in advance for your reply!

Kangcor
  • 1,179
  • 1
  • 16
  • 26

4 Answers4

1

you can use <div ng-repeat="user in value | filter: query as results"> and then get results.length

see example here: http://plnkr.co/edit/P0ORxHkVpreANErDGc3a?p=preview

Alex Barannikov
  • 304
  • 2
  • 8
1

You can do this http://jsfiddle.net/HB7LU/10720/

<div ng-repeat= "user in filteredValue = (value | filter:query)"></div>

Just use the filtered result as another scope variable, named filteredValue , then you can get its length, within the scope of the controller

Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88
1

It might help you!! Its use for prints filtered number of users.

{{(data|filter:query).length}}
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Anil Singh
  • 4,173
  • 4
  • 41
  • 47
0

As seen in this other question

Assign the filtered data in a variable

<div ng-repeat="user in filtered = (users | filter: query)">
</div>

And use the filtered.length attribute to get the count

Community
  • 1
  • 1
Kangcor
  • 1,179
  • 1
  • 16
  • 26