I have come across below example in Angular 2 documentation
@Component({
selector: \'cmp\',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `Num
With ChangeDetectionStrategy.OnPush
Angular runs change detection, when in @Input()
was updated, a DOM event Angular listens to was received, or the async pipe (| async
) received a new value.
If you for example subscribe to an observable from a service and update the status of the component, bindings to this status won't be updated, because this is not covered by above list. If you call this.ref.markForCheck()
you tell Angular that it should run change detection because there actually are changes that need to be updated (that's also what the async pipe does).
Other cases are if you explicitly (this.zone.runOutsideAngular()
) or for some other reasons code runs outside Angulars zone modifies the status of the component, this also won't be covered (even when the code is an event handler).