OnPush Change Detection
Reduce checks with OnPush strategy.
The Performance Problem
The default strategy checks every component on every tick. In large apps this adds up. OnPush tells Angular to skip a component unless something relevant changed.
Enabling OnPush
Set the changeDetection option on the component.
@Component({
selector: 'app-user',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '{{ user().name }}'
})
export class UserComponent {}All lessons in this course
- How Change Detection Works
- OnPush Change Detection
- Zoneless Angular
- Optimizing Lists and Rendering