Why event triggers ChangeDetection even if OnPush strategy is ON?

时间:2017-08-04 12:59:23

标签: 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.

1 个答案:

答案 0 :(得分:6)

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

相关问题