Determining How Many Results Are Shown By Ng-repeat Filter
Solution 1:
Please see here http://jsbin.com/xuyuy/1/edit
In your repeater you can create new array ie : personsfiltered
ng-repeat="person in personsfilterd = (persons | filter : search )
and after that just display length of orignal array and filtered array :
Showing {{personsfilterd.length}} of {{persons.length }} results
Full code here:
var app = angular.module('app', []);
app.controller('fCtrl', function($scope) {
$scope.persons = [
'Mike', 'Tom', 'Tim', 'Jim', 'Ken'
]
});
<divng-app="app"><divng-controller="fCtrl"><inputtype="text"ng-model = "search"> Showing {{personsfilterd.length}} of {{persons.length }} results
<ling-repeat="person in personsfilterd = (persons | filter : search )">{{person}}</li></div></div>
Solution 2:
First, the ngRepeat
has these: $index
, $first
, $middle
, $last
for determining the current position. So I guess you may be interested in the $last
. What I'm not sure about is whether it will pick up the original count or the filtered one.
EDIT:
You can obtain the count of original value from your ctrl, by setting the varX.length
and using that in your template (HTML code) and then, assuming that $last
is returning the final count+1 (as it's 0-based) you can have the count after filter is applied.
Solution 3:
I found my answer here. The solution is to assign the filtered data to a new variable in the ng-repeat
. Potentially could cause some memory issues, but not really relevant in my case.
Post a Comment for "Determining How Many Results Are Shown By Ng-repeat Filter"