我想在更改多维范围变量(例如,添加元素,删除元素等)时触发一个事件。我尝试使用$ scope。$ watch和$ scope。$ watchCollection来执行此操作,但它不起作用。
这是方案。
$scope.variable=[{ID:1,text:'abc'},{ID:1,text:'abc'}];
$scope.content='';
$scope.$watch('$scope.variable',function(){
$scope.content=$scope.variable[0].text;
});
有什么帮助吗?
添加true
为参数
$scope.$watch('variable',function(){
$scope.content=$scope.variable[0].text;
}, true);
注意:不需要$scope
in参数
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句