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
Release: 2024-11-09 20:09:02
Original
614 people have browsed it

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>
Copy after login

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

Showing {{filtered.length}} Persons
Copy after login
Copy after login

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>
Copy after login
Showing {{filtered.length}} Persons
Copy after login
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template