Junior
From PDF
Angular
Angular
What is ngZone, and how does it relate to Angular’s change detection? ● Angular uses NgZone to detect asynchronous events (like clicks, timers, HTTP). ● NgZone runs code inside Angular's zone, triggering change detection
utomatically.
- You can run code outside Angular's zone to prevent unnecessary change
detection.
✅ Example:
constructor(private ngZone: NgZone) {}
runHeavyTaskOutsideAngular() {
this.ngZone.runOutsideAngular(() => {
// code here won't trigger change detection
});
}Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png