NgZone vs ChangeDetectorRef (CDR) in Angular
Both NgZone and ChangeDetectorRef (CDR) help with change detection, but they serve different purposes.
๐น NgZone
NgZone is a service that controls how Angular detects changes globally across the application. It helps manage execution inside or outside Angular's change detection system.
✅ When to Use NgZone?
- Running non-Angular events (like 
setTimeout, WebSockets, or third-party libraries) inside change detection. - Skipping change detection for performance (e.g., animations, timers).
 
๐น Key Methods:
run(callback) → Forces Angular to detect changes.runOutsideAngular(callback) → Runs code outside change detection (for performance).
Example: