$scope.$watch 仅在 AngularJS 中删除类别表单树视图时起作用
$scope.$watch works just at deleting category form treeview in AngularJS
我有一个简单的应用程序,在页面上有 类别和电话的树状视图:
<div id="treeView">
<div dx-tree-view="treeViewOptions"></div>
</div>
我在控制器中编写了 watch 函数:
$scope.$watch('treeViewOptions', function () {
console.log("TreeView was changed");
});
但是在我删除类别后,控制台中会显示消息
可能有人知道我如何检查我的 treeview 中的所有更改?
感谢您的回答!
您应该将 objectEquality 设置为 "true"
$scope.$watch('treeViewOptions', function () {
console.log("TreeView was changed");
}, true);
来自https://docs.angularjs.org/api/ng/type/$rootScope.Scope
$watch(watchExpression, listener, [objectEquality]);
When objectEquality == true, inequality of the watchExpression is determined according to the angular.equals function. To save the value of the object for later comparison, the angular.copy function is used. This therefore means that watching complex objects will have adverse memory and performance implications.
我有一个简单的应用程序,在页面上有 类别和电话的树状视图:
<div id="treeView">
<div dx-tree-view="treeViewOptions"></div>
</div>
我在控制器中编写了 watch 函数:
$scope.$watch('treeViewOptions', function () {
console.log("TreeView was changed");
});
但是在我删除类别后,控制台中会显示消息 可能有人知道我如何检查我的 treeview 中的所有更改? 感谢您的回答!
您应该将 objectEquality 设置为 "true"
$scope.$watch('treeViewOptions', function () {
console.log("TreeView was changed");
}, true);
来自https://docs.angularjs.org/api/ng/type/$rootScope.Scope
$watch(watchExpression, listener, [objectEquality]);
When objectEquality == true, inequality of the watchExpression is determined according to the angular.equals function. To save the value of the object for later comparison, the angular.copy function is used. This therefore means that watching complex objects will have adverse memory and performance implications.