AngularJS - how to set up $watch on multiple values -


i need watch on model changes in object sits in controller. object has multiple values:

$scope.mymodel = {    first: 1,    second: 1,    third: 1 } 

i want catch changes of these values, don't want set multiple watchers on each individual value, seems wasteful. can set 1 $watch triggers when in model has changed?

pass true third argument $watch function, see docs scope :

$watch(watchexpression, [listener], [objectequality]);
(...) objectequality: compare object equality using angular.equals instead of comparing reference equality

when objectequality false or not set, means check if it's same object or not. instead, setting true check if equal or not.

so watch like:

$scope.$watch('variable', function(newvalue, oldvalue) {     // function code }, true); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -