OnPush strategy triggers change detection only when input references change, events occur, or manual triggers happen. Mutating an object property without changing its reference does not trigger update.
import { Component, ChangeDetectionStrategy } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; @Component({ selector: 'app-counter', template: `<div>{{ counter$ | async }}</div>`, changeDetection: ChangeDetectionStrategy.OnPush }) export class CounterComponent { counter$ = new BehaviorSubject(0); constructor() { setTimeout(() => { this.counter$.next(1); }, 2000); } }
The async pipe subscribes to the observable and triggers change detection when new values arrive, even with OnPush strategy. So the displayed value updates from 0 to 1 after 2 seconds.
ngOnChanges is called only when Angular detects a change in the reference of an @Input() property, even with OnPush strategy.
The correct property name is changeDetection and it must be assigned the enum value ChangeDetectionStrategy.OnPush. Using a string or wrong property name causes errors.
Parent template: <app-child [data]="user"></app-child> Parent component: user = { name: 'Alice' }; updateName() { this.user.name = 'Bob'; } Child component: @Component({ selector: 'app-child', template: `{{ data.name }}`, changeDetection: ChangeDetectionStrategy.OnPush }) export class ChildComponent { @Input() data!: { name: string }; }
OnPush triggers change detection only when input references change. Mutating a property inside the object does not change the reference, so the child does not update.