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
Post a Comment