Reputation: 33059
I have this in my Angular app:
myApp.value(mySetting, mySettingValue);
Is it possible to $watch()
mySetting
for changes? I've tried but can't get it to work.
This doesn't seem to do the trick:
$rootScope.$watch(function() {
return mySetting;
, function(newSettingValue) {
console.log(Date.now() + ' ' + newSettingValue);
});
Upvotes: 1
Views: 31
Reputation: 136134
You missed to true
property as a 3rd parameter inside your $watch
, adding true
will keep deep watch on object
Code
$rootScope.$watch(function() {
return mySetting;
, function(newSettingValue) {
console.log(Date.now() + ' ' + newSettingValue);
}, true);
Upvotes: 1