Stepan Suvorov
Stepan Suvorov

Reputation: 26146

Why event triggers ChangeDetection even if OnPush strategy is ON?

When we use Default Strategy this guys could trigger Change Detection(of course except input params):

BUT. When you switch to OnPush Strategy it's trigger only by events and does not work for timers and http.

So the questions is why it does not work for times and https or why it works for events.

Upvotes: 7

Views: 2757

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657078

OnPush is defined this way.

It triggers change detection

  • when a DOM event the component listens to was received
  • when the |async pipe receives a new event
  • when an @Input() was updated by change detection.
  • when explicitly registering the component to be checked the next change detection turn using ChangeDetectorRef::markForCheck

ChangeDetectionStrategy.Default triggers change detection for every async callback called within Angulars zone (every DOM even listened to within the Angular application, every Observable event or completed Promise, setTimeout, ...)

Upvotes: 13

Related Questions