gpt4 book ai didi

javascript - Angularjs $scope.$watchCollection 仅第一级属性

转载 作者:行者123 更新时间:2023-11-30 17:02:33 25 4
gpt4 key购买 nike

$scope.$watchCollection 用于更改对象中的属性时,它仅评估第一级属性。当调用 $scope.$watchCollection 时,有没有办法强制 angular 评估第二级或更低级别?

最佳答案

您正在寻找的是 $scope.$watch(watchExpression, listener, [objectEquality]); 其中第三个参数“objectEquality”为 true

  • The watchExpression is called on every call to $digest() and should return the value that will be watched. (Since $digest() reruns when it detects changes the watchExpression can execute multiple times per $digest() and should be idempotent.)
  • The listener is called only when the value from the current watchExpression and the previous call to watchExpression are not equal (with the exception of the initial run, see below). Inequality is determined according to reference inequality, strict comparison via the !== Javascript operator, unless objectEquality == true (see next point)
  • 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. The watch listener may change the model, which may trigger other listeners to fire. This is achieved by rerunning the watchers until no changes are detected. The rerun iteration limit is 10 to prevent an infinite loop deadlock.

https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$watch

关于javascript - Angularjs $scope.$watchCollection 仅第一级属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28590531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com