I've fixed it using scope.$watchCollection after the loop 
using the data collected during it, like this 


scope.$watchCollection('[' + props.join() + 
']',function(newValues,oldValues){
  props.forEach(function(entry, index) {
    // do something
  });
});

anyway I am still curious to know if it is possible to use $watch 
in a loop and how.

Cheers





Il giorno giovedì 27 novembre 2014 14:33:32 UTC+1, Sergio Rinaudo ha 
scritto:

> Hi everyone, 
> I'm trying to use the scope.$watch function *within a loop* and I cannot 
> make it work as expected.
>
>
> The code is something like this
>
> for(var i in control.children) {
>   scope.$watch(
>       control.children[i].propertyId,
>       function(newValue, oldValue) {
>         if ( newValue !== oldValue ) {
>           // do something
>         }
>       }
>   );
> }
>
>
> As you can see the first parameter of scope.$watch depends by the current 
> loop index.
>
> When edit *any* of the watched model the watcher that run is always the 
> latest registered 
> by the loop.
>
>
> The question is, it is possible to use watchers within a loop?
>
> Thanks
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to