angularjs - How to $watch changes in array item but not the array itself -


for example have

$scope.array = [{ foo: 'bar'}, { foo: 'bar2'}] 

i want watch array such that

$scope.array.pop(); //$watch not called $scope.array[0].foo = 'newbar'; //$watch called $scope.array = [{ foo: 'bar' }, { foo: 'anotherbar' }]; //$watch not called 

is possible accomplish $scope.$watch?

you can use function return required value watch:

$scope.$watch(function(scope) { return scope.array && scope.array[0].foo; }, function(newvalue, oldvalue) {     // action here     } ); 

if need observe more itens, can return array foo's objects, example.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

dataset - MPAndroidchart returning no chart Data available -

post - imageshack API cURL -