What is the difference between default and onPush change detection strategies in Angular?
Change
Detection
Strategy
Description When to Use
Default Angular checks every
component in the component
tree every cycle
Simple apps or components with
frequent changes
OnPush Angular checks component only
if input references change or
events
Optimizes performance, suitable
for immutable data & smart
components
How to set OnPush:
@Component({
selector: 'app-example',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `...`
})
export class ExampleComponent {}
Key Difference:
- Default: Runs change detection every time.
- OnPush: Runs only when inputs change by reference or manual trigger.