Remove and restore Scope from digest cycles

后端 未结 2 1418
忘掉有多难
忘掉有多难 2021-02-19 21:37

Is there a way to remove a scope from the digest cycles? In other words, to suspend/resume a scope digest cycle?

In my case, I have all pages already loaded, but not all

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-19 22:20

    As the framework stands today there are no methods to suspend / resume digest on a scope. Having said this there are several techniques that one can use to limit number of watches that are executed as part of a digest cycle.

    First of all, if parts of a screen are hidden anyway you could use the ng-switch family of directives thus removing invisible parts completely from the DOM.

    Secondly, if a digest cycle is triggered from your directive via $apply and you want to limit watches re-evaluation to child scopes you could call $digest instead of $apply.

    Then, yes, one could destroy and re-create scopes as described in the discussion you've linked to. But, if you are already hiding parts of the DOM it sounds like ng-switch might be a better option.

提交回复
热议问题