Angularjs 如何检测角度js中多维数组的模型变化
我想在多维范围变量发生更改时触发一个事件,即添加、删除元素等。我尝试使用$scope.$watch和$scope.$watchCollection执行此操作,但它不起作用 情况就是这样Angularjs 如何检测角度js中多维数组的模型变化,angularjs,multidimensional-array,angularjs-scope,Angularjs,Multidimensional Array,Angularjs Scope,我想在多维范围变量发生更改时触发一个事件,即添加、删除元素等。我尝试使用$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
$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
$scope.$watch('variable',function(){
$scope.content=$scope.variable[0].text;
}, true);