Angular: Disable Change Detector for an entire class (service or component)

后端 未结 3 490
终归单人心
终归单人心 2021-01-24 20:07

Is there a way to completely disable Angular\'s change detector if events that normally cause the change detection to run (setTimeout, setInterval, browser events, ajax calls et

3条回答
  •  猫巷女王i
    2021-01-24 20:39

    Change Detection starts at the very top of your component tree and is triggered by zone.js. An async operation like setTimeout is picked up by zone.js which notifies angular that changes might have happened. Angular then runs change detection top-down on the component tree. Detaching a single class from the change detector will cut out that class (i.e. directive) from change detection but won't stop change detection from being run on the rest of your component tree. For your needs ngZone.runOutsideAngular(...) is the way to go, because it stops zone.js from notifying angular about your async operation thus entirely preventing change detection from being run.

提交回复
热议问题