Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why event triggers ChangeDetection even if OnPush strategy is ON?

Tags:

angular

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

  • user events
  • timers
  • ajax response

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.

like image 439
Stepan Suvorov Avatar asked Aug 04 '17 12:08

Stepan Suvorov


1 Answers

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, ...)

like image 78
Günter Zöchbauer Avatar answered Oct 13 '22 01:10

Günter Zöchbauer