Count filtered items in ng-repeat

5,795 views
Skip to first unread message

Leo Nistor

unread,
May 15, 2012, 6:20:44 AM5/15/12
to ang...@googlegroups.com
I'm trying to count and display the number of filtered items within a ng-repeat: http://jsfiddle.net/leonistor/E9prv/25/ by keeping a variable in the model ($scope).

But as soon as I try to touch it (the commented lines in the filterSearch function) an error is thrown -- "Uncaught Error: 10 $digest() iterations reached. Aborting!", and the value is wrong. I understand from previous posts that the model is "mutating" itself, and since the $count method isn't available any more I can't think of other way to accomplish my goal.

Could you offer some suggestions? (I know it's a newbie question, I'm still struggling to understand AngularJS concepts, but it's so beautiful it's worth the effort!)

Thank you!
Leo

Toshihide Shimayama

unread,
May 15, 2012, 9:37:42 AM5/15/12
to ang...@googlegroups.com
I think you can simply look at 'length' property of the filtered array.
http://jsfiddle.net/2zFAv/

But it'll filter twice and may be slow...

Thanks
--tosh shimayama

2012年5月15日火曜日 6時20分44秒 UTC-4 Leo Nistor:

Andy Joslin

unread,
May 15, 2012, 9:40:41 AM5/15/12
to ang...@googlegroups.com
Doing the filtering completely in the controller using $filter service is probably the most efficient way to do this: http://jsfiddle.net/andytjoslin/E9prv/26/

Vojta Jína

unread,
May 22, 2012, 2:00:32 AM5/22/12
to ang...@googlegroups.com
Yep, doing it in the controller only once is the right way.
Even if you don't need the length property, it would be more efficient.

V.
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/angular/-/mkRaQQoD4QkJ.
>
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/angular?hl=en.

Cyril Lakech

unread,
Mar 13, 2013, 10:29:41 AM3/13/13
to ang...@googlegroups.com
Have you tried:

ng-repeat="attribute in (filteredLinkAttributes = (selectedNetchandisingNode.model.attributes | filter:attributesLinkFilter))"

and then use scope.filteredLinkAttributes to calculate lenght

Rgds

Jorge Braccini

unread,
Jun 6, 2013, 2:00:24 PM6/6/13
to ang...@googlegroups.com
Nice one!

shanthi B

unread,
Jun 25, 2015, 8:37:12 AM6/25/15
to ang...@googlegroups.com
Hi,

Can u please send me an example on that.
My problem here is, say my object object = {"xyz":{name:"shanthi", isFemale:true}, "abc":{name:"john",isFemale:false}}
I want the count of the isFemale  false, so how i can i get that number by filtering?
Reply all
Reply to author
Forward
0 new messages