Yep, you'd have to loop through to determine which was changed $watching an 
array.  (I don't think you want to $watch each object in array, bad idea) 
 Comparing objects isn't too difficult with 
angular.equals: http://docs.angularjs.org/api/ng/function/angular.equals

But, I have to ask what causes the change on the object that you need 
watch?  If it is from the ui view then you can put the call on the element 
and move the function on the scope:

< li ng-repeat="item in myArray">
  <input ng-model="item.name" ng-change="doSomethingWith('name',item)">
</li>

$scope. doSomethingWith(key, item){
    //now we know exactly what changed on the object and can do what we 
need with it
    console.log( 'item name is now ', item[key]  )
}

See: http://docs.angularjs.org/api/ng/directive/ngChange

On Friday, March 14, 2014 11:42:40 PM UTC-6, Disha Shah wrote:
>
> I am kinda new to Angular JS, and am trying to figure out a elegant 
> solution to watch each object in a array for its property changes.
> I know the way to deep watch an array is by:
>
> $scope.$watch("collection",function( newValue, oldValue ) {
>     /* do something*/
>  }, true );
>
> But the newValue, oldValue doesn't give away exactly which object in the 
> array has changed. 
> Other way I can think of is to loop the array and set a watch on each object 
> in the array. 
>
> Is there a better solution to this?
>
>

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