Discover how a simple setting can make your Angular app feel lightning fast!
Why When to use OnPush in Angular? - Purpose & Use Cases
Imagine you have a big Angular app with many components, and every time something changes anywhere, Angular checks all components to see if they need updating.
This can slow down your app and make it feel laggy.
Without optimization, Angular runs change detection on every component all the time, even if nothing changed in some parts.
This wastes time and computer power, making your app slower and less smooth.
Using OnPush tells Angular to only check a component when its input data changes or an event happens inside it.
This way, Angular skips unnecessary checks and your app runs faster and smoother.
changeDetection: ChangeDetectionStrategy.Default
changeDetection: ChangeDetectionStrategy.OnPush
OnPush enables your app to run efficiently by reducing unnecessary work, making it faster and more responsive.
Think of a social media feed where only new posts or likes update the screen, instead of rechecking every post all the time.
Without OnPush, Angular checks all components often, slowing the app.
OnPush limits checks to when inputs change or events occur.
This improves app speed and user experience.