Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I have a data array which contains many objects (JSON format). The following can be assumed as the contents of this array:

var data = [ 

 { 

  "name": "Jim", 

  "age" : 25 

 }, 

 { 

  "name": "Jerry", 

  "age": 27 

 } 

];

Now, I display these details as:

<div ng-repeat="person in data | filter: query"> </div

Here, the query is modelled to an input field in which the user can restrict the data displayed.

Now, I have another location in which I display the current count of people/person being display, i.e Showing {{data.length}} Persons

What I want to do is that when the user searches for a person and the data displayed is filtered based on the query, the Showing...persons also change the value of people being shown currently. But it is not happening. It always displays the total persons in data rather than the filtered one - how do I get the count of filtered data?

1 Answer

+1 vote
by (106k points)

To display the length of filtered ng-repeat data the easiest way would be to use the below-mentioned way:-

<div ng-repeat="person in data | filter: query"></div>

You can also use the filtered data length which is as follows:-

<div>{{ (data | filter: query).length }}</div>

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...