Assigning ng-repeat filtered result set only works for nested property names

25 views
Skip to first unread message

Torsten Uhlmann

unread,
Aug 18, 2014, 8:13:30 AM8/18/14
to ang...@googlegroups.com
Hi,

I hope the title of the post is not too misleading...

I tried to access the filter result created inside an ng-repeat inside my controller as demonstrated in this fiddle: http://jsfiddle.net/jvandyke/EAbks/2/

<li ng-repeat='item in filteredItems = (items | filter:filterExpr)'>{{item}}</li>

Doing it like this does allow my to access the "filteredItems" var inside the template ({{filteredItems.length}}), but I was not able to get a hold of it inside the controller.

However, if I create a js object "var $scope.filtered={};" and then change ng-repeat to:

<li ng-repeat='item in filtered.filteredItems = (items | filter:filterExpr)'>{{item}}</li>

the $watch expression would acknowledge changes to the var and I was able to access it without any problems.

We use Angular 1.2.16 in our project. Could this be related to some setup issue?

Thanks,
Torsten.

Sander Elias

unread,
Aug 18, 2014, 8:52:49 AM8/18/14
to ang...@googlegroups.com
Hi Torsten,

Assuming from your code, this code is part of another ng-repeat right? (or at least the child of another directive that creates a new scope!)
Every repeated item has its own new scope. You can't access a child-scope property from the controller.
However, objects are linked by reference, that's why your second solution works.

Does this make sense to you?

Regards
Sander Elias

Torsten Uhlmann

unread,
Aug 18, 2014, 9:09:35 AM8/18/14
to ang...@googlegroups.com
Hi Sander,

I get what you're saying. 
This ng-repeat is not part of another ng-repeat and I also didn't find another surrounding directive that does create its own scope.

I could be wrong though, need to check more thorough. However your explanation makes sense.

Thanks,
Torsten.



--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/Zsg9WM1KAGI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
AGYNAMIX(R). Passionate Software.
Inh. Torsten Uhlmann | Buchenweg 5 | 09380 Thalheim
Phone:     +49 3721 273445
Fax:         +49 3721 273446
Mobile:     +49 151 12412427
Web:        http://www.agynamix.de
Reply all
Reply to author
Forward
0 new messages