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
});
}