Home >Web Front-end >JS Tutorial >How to Display the Length of Filtered Data in Angular's `ng-repeat` Directive?

How to Display the Length of Filtered Data in Angular's `ng-repeat` Directive?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-09 20:09:02618browse

How to Display the Length of Filtered Data in Angular's `ng-repeat` Directive?

Displaying Length of Filtered ng-repeat Data

As you have an ng-repeat directive displaying data filtered by user input, you want the displayed count of people to reflect the filtered results.

In Angular 1.3 , you can use an alias expression to achieve this:

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

The "filtered" alias represents the filtered array, which you can then use to display the count:

Showing {{filtered.length}} Persons

Prior to Angular 1.3, you can assign the filtered results to a new variable and access it:

<div ng-repeat="person in filtered = (data | filter: query)">
</div>
Showing {{filtered.length}} Persons

This way, the "filtered" variable will contain the filtered results, and the count will accurately display the number of filtered people.

The above is the detailed content of How to Display the Length of Filtered Data in Angular's `ng-repeat` Directive?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn