How to display length of filtered ng-repeat data?
How to display length of filtered ng-repeat data?
256
17-Jun-2024
Updated on 19-Jun-2024
Ashutosh Kumar Verma
19-Jun-2024Length of ng-repeat data
To specify the length of changed data in
ng-repeat
in AngularJS (assuming you are using AngularJS based onng-repeat
), you can follow these steps:Create a Filtered Array- Use AngularJS filters to create a new layout with only changed objects based on your criteria.
Display the Length- Use AngularJS expressions ({{ }}) or directives to specify the length of the modified layout.
Filter the Data
Imagine you have an array of items that you iterate using
ng-repeat
. You can use AngularJS filters (filter in this case) to get items that match certain criteria.Example-
Let's take an input field where you can filter items based on a property called search
In the example above
ng-model="search"
Binds the input field value to the search variable.filter: search"
Filters the items based on the search property that matches the value in the search.Display the Length of Filtered Data
To specify the length of the filtered data, you can use a modified order with the
filter
array. Here's how you can determine the length.In the syntax above
(
items | filter: search
) Filter items based on the current value of the search..length
returns the length of the filtered items.Example-
In the example above-
<input>
field with propertysearch
for filtering the items from collection<p>
tag shows the length of the filtered items usingdata-ng-bind="(names | filter : search).length"
data-ng-repeat="data in names | filter : search"
is used to bind the updated data into the table every timeOutput-
Also, Read: Adding multiple class using ng-class