I am trying to understand how best to achieve the following in angularjs.
1) I have an array of objects:
$scope.myArray = [{special:false, name:'alice'}, {special:false, name:'bob'}];
if myArray[0].special changes to true, using $watch how can I detect that this was because of a change in element 0 of the array. Everything I have read on $watch deals with notifying that the array as a whole as changed but there is no way to retrieve the element/index of the array that has changed. I want to have this cope with varying lengths of arrays, so it would not suffice to simply have:
$scope.watch('myArray[0].special')
2) I have a dictionary:
$scope.myValues = {id1:{special:false, name:'alice'}, id2:{special:false, name:bob'}};
a similar question - if I was to change myValues.id1.special to true, how could I get the corresponding name field (or know it was id1)?
I would really appreciate any help and guidance here on best practice and what is actually possible with angularjs and $watch (or $watchcollection) with respect to arrays and maps. I think this is similar to question Watch angular array of objects and animate the changed property but I'm also interested to see how to watch across all properties in a dictionary.
Many many thanks in advance.