Hi folks,

Can someone illuminate me why $scope.$watch() accepts a watch expression 
($scope.$watch('myObj.thing')) and not an object 
($scope.$watch(myObj.thing))?

Was the expression syntax used to make implementation more 
straight-forward, or are there benefits from a design perspective?

Here's a case where the expression syntax breaks down, watching individual 
items in an array. To do this today you'd need to do the following:

for (var i=0; i < listOfObjs.length-1; i++){
   $scope.$watch('listOfObjs['+i+']', cb); // generating a string of 
'listOfObjs[0]', which of course is super weird
}

vs.

_.each(list, function(item){$scope.$watch(item, cb);} // ah nice

And if it wasn't clear, this is not a use case for watchCollection or deep 
watch a list, because those return the full array itself to the watch 
callback, not the item changed.

-Michael

-- 
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