Problem Statement
What is NgZone and how does it relate to change detection?
Explanation
NgZone tracks async tasks (timers, XHR) and triggers change detection when they complete. For performance-critical scenarios, you can run code outside Angular’s zone to avoid unnecessary checks and then re-enter to update the UI.
Code Solution
SolutionRead Only
constructor(private zone: NgZone){}
heavy(){ this.zone.runOutsideAngular(() => { expensiveWork(); this.zone.run(() => this.ready = true); }); }Practice Sets
This question appears in the following practice sets: