Angularjs get length of returned filter in ng-repeat


I'm using ng-repeat to create a list of entires and using a filter.

Is it possible to get the number of entries returned, like a length

    data-ng-repeat="entry in entries | filter: { country_code : countryCode }"
Problem courtesy of: ttmt


It is little bit tricky, use ng-init:

ng-init="filter_len = (entries | filter: { country_code : countryCode }).length" 


Solution courtesy of: Cherniv


I suppose the following code will work for you:

<p>Filtered number: {{(entries|filter:{country_code:countryCode}).length}}</p> <p>Total number: {{entries.length}}</p>

Discussion courtesy of: Wei WANG

As you know filter responsible to "filter" the input list and it returns filtered list where objects have the same structure. Otherwise you get digest cycle reentering that causes Exceptions (aka > 10 cycles).

1st way

Get length after filtering:

<pre>{{(entries| myfilter:types).length }}</pre>

See Example

2nd way

Use custom filter and get length from there.

iApp.filter('myfilter', function() {

   return function( entries) {
    var filtered = [];

    angular.forEach(entries, function(entry) {

    // here fetch list length

    return filtered;
Discussion courtesy of: Maxim Shoustin

This recipe can be found in it's original form on Stack Over Flow.