Changing controller-level variables inside an ng:repeat doesn't work...

246 views
Skip to first unread message

Nick R

unread,
Nov 11, 2011, 8:08:55 PM11/11/11
to ang...@googlegroups.com
In the process of debugging this I found a work-around.  I just find this kind of strange:


If you click on "Inside Data2", nothing happens.  If you run a debugger and step through the code, it looks like it's doing what it's supposed to: assigning this.data to this.data2.  Before it makes the assignment, this.data is data1, as it should be.  However, after it makes the assignment, the template does not change.

I noticed, however, that it works fine if you do the same thing only outside of the ng:repeat.  And it also works if you give it a $parent.  But based on stepping through the code, it looks like it should work regardless, right?  Unless the ng:repeat is copying all the variables from the outer scope into its own, running the controller methods in its own context, and not propagating the values back up.  I didn't know it could run the controller methods in its own context.

Does this mean that you can make a controller-level variable and override it in a particular iteration of ng:repeat if you want?  I guess so.  So, sorry for wasting your time with this.  I just didn't expect it to work this way.

Vojta Jina

unread,
Nov 12, 2011, 1:35:41 AM11/12/11
to ang...@googlegroups.com
Hi Nick,

- ng:repeat creates new scope per row
- scope inherit by prototype

so, your code change the child scope, but ng:repeat repeats over the property of parent scope...

You have two options to do that:

2/ define the method in prototype - because all prototype methods are binded to the related scope (the scope where the controller is defined, in our example, <ul> element):

Hope this helps...

V.
Reply all
Reply to author
Forward
0 new messages