gpt4 book ai didi

javascript - 如果还调用了 $doChanges,$doCheck 如何不会产生任何影响?

转载 作者:行者123 更新时间:2023-12-03 06:29:27 25 4
gpt4 key购买 nike

AngularJS official documentation就此提供了以下信息。

$doCheck() - Called on each turn of the digest cycle. Provides an opportunity to detect and act on changes. Any actions that you wish to take in response to the changes that you detect must be invoked from this hook; implementing this has no effect on when $onChanges is called. For example, this hook could be useful if you wish to perform a deep equality check, or to check a Date object, changes to which would not be detected by Angular's change detector and thus not trigger $onChanges. This hook is invoked with no arguments; if detecting changes, you must store the previous value(s) for comparison to the current values.

我在网上进行了探索,但找不到任何与调用 $onChanges 如何使对 $doCheck 的调用无效相关的信息。请有人提供更多信息。

最佳答案

$onChanges$doCheck Hook 可以轻松并存。 $doCheck Hook 根本不会影响 $onChanges Hook 。当然,在 $doCheck Hook 中检查的字段不再需要在 $onChanges Hook 中处理。在 Angular 2 中,甚至建议不要同时使用这两个钩子(Hook)。

关于javascript - 如果还调用了 $doChanges,$doCheck 如何不会产生任何影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38505142/

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