Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 关注价值服务价值?_Angularjs_Watch - Fatal编程技术网

Angularjs 关注价值服务价值?

Angularjs 关注价值服务价值?,angularjs,watch,Angularjs,Watch,我的Angular应用程序中有: myApp.value(mySetting, mySettingValue); 是否可以$watch()mySetting进行更改?我试过了,但没能成功 这似乎不起作用: $rootScope.$watch(function() { return mySetting; , function(newSettingValue) { console.log(Date.now() + ' ' + newSettingValue); }); 您未将tr

我的Angular应用程序中有:

myApp.value(mySetting, mySettingValue);
是否可以
$watch()
mySetting
进行更改?我试过了,但没能成功

这似乎不起作用:

$rootScope.$watch(function() {
    return mySetting;
, function(newSettingValue) {
    console.log(Date.now() + ' ' + newSettingValue);
});

您未将
true
属性作为
$watch
中的第三个参数,添加
true
将对对象进行深入监视

代码

$rootScope.$watch(function() {
    return mySetting;
, function(newSettingValue) {
    console.log(Date.now() + ' ' + newSettingValue);
}, true);

您是否尝试为深度检查手表添加
true
。类似于
$rootScope.$watch(函数(){return mySetting;,函数(newSettingValue){console.log(Date.now()+“”+newSettingValue);},true)
watch在更改常量值后启动。.查看plnkr,是的,手表第一次启动-只有一次,以后更改时不会启动。:)忘记添加true,现在在单击按钮时选中此选项watch被称为submit this as answer