Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

There is an array of objects in my scope, I want to watch all the values of each object.

This is my code:

function TodoCtrl($scope) { 

$scope.columns = [ 

{ field:'title', displayName: 'TITLE'}, 

{ field: 'content', displayName: 'CONTENT' } 

]; 

$scope.$watch('columns', function(newVal) {

 alert('columns changed'); 

 }); 

}

But when I modify the values, e.g. I change TITLE to TITLE2, the alert('columns changed') never popped.

How to deep watch the objects inside an array? 

1 Answer

0 votes
by (106k points)
edited by

Do deep watch an array in angularjs you can set the 3rd argument of $watch to true:-

Are you interested in learning Angularjs from the basics! Here's the right video for you on Angularjs provided by Intellipaat:

$scope.$watch('data', function (newVal, oldVal) { /*...*/ }, true);

Related questions

0 votes
1 answer
0 votes
1 answer
+2 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...