Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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
Javascript 监视自定义指令属性在父范围更改时不更改_Javascript_Angularjs - Fatal编程技术网

Javascript 监视自定义指令属性在父范围更改时不更改

Javascript 监视自定义指令属性在父范围更改时不更改,javascript,angularjs,Javascript,Angularjs,我在另一个自定义指令中有一个自定义指令,我希望子指令在其父指令更改范围值时更改 父指令的html有一个称为childHeight的作用域变量,我有一个设置它的函数 <button ng-on-click="setHeight(500)"> change the height </button> <child-directive ctrl-height="childHeight"></child-directive> 当我在setHeight中更改

我在另一个自定义指令中有一个自定义指令,我希望子指令在其父指令更改范围值时更改

父指令的html有一个称为childHeight的作用域变量,我有一个设置它的函数

<button ng-on-click="setHeight(500)"> change the height </button>
<child-directive ctrl-height="childHeight"></child-directive>
当我在setHeight中更改scope变量时

$scope.childHeight = 500;
为什么手表没有被触发


我尝试添加一个$apply()或$digest,两者都会给我一个错误

如果您需要同时查看
ctrlHeight
ctrlWidth
,您可以尝试以下操作:
scope.$watch('ctrlHeight+ctrlWidth',watcher)

这样,每次它们发生变化时,就会触发您的
watcher
fn。另外,
$apply()
将无法工作,因为您已处于角度上下文中。

错误:[$rootScope:inprog]$apply已在进行中我认为问题在于我的集合ctrlHeight实际上是根据字符串而不是范围变量计算的。所以,当我用2美元的手表,一块宽度,一块高度时,它就工作了。
$scope.childHeight = 500;