1

Angular2 uses the concept of Zones to remove the need to manually do a view update. That's all great but, when does Angular2 decide to do a view update ?

After reading this article I have got the notion that Angualar2 does a view update on almost every event. Even on a mousemove event !! Is that true ?

Because if it is, its damn computationally expensive.

ng.newbie
  • 2,807
  • 3
  • 23
  • 57
  • This question can be related http://stackoverflow.com/questions/40300635/angular-2-runoutsideangular-still-change-the-ui – yurzui Dec 02 '16 at 09:54

1 Answers1

2

Depends on what you mean with an "event". Angular doesn't update on events no event listeners are registered for from within Angular2.

Angular also doesn't update just because of an event, it just runs change detection to see if something needs updating.

With ChangeDetectionStrategy and other measures you also can limit which parts of your application it runs change detection on.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • So a change detection is fired every time, a mouse move event is fired ? Isn't that also pretty inefficient ? – ng.newbie Dec 02 '16 at 07:11
  • As I said it only checks if there are event handlers registered for that event. If there is an event handler, it's likely the handler somehow changed state, therefore it's reasonable to detect changes. – Günter Zöchbauer Dec 02 '16 at 07:14
  • Also again. You have fine grained control what parts of your application should be checked for changes. The default is not the most efficient setting, but still quite efficient, but it's the easiest for getting started. – Günter Zöchbauer Dec 02 '16 at 07:17
  • Any docs or tutorial on how to change the default setting for change detection ? – ng.newbie Dec 02 '16 at 08:36
  • http://blog.thoughtram.io/angular/2016/02/22/angular-2-change-detection-explained.html, http://blog.angular-university.io/how-does-angular-2-change-detection-really-work/, https://vsavkin.com/change-detection-in-angular-2-4f216b855d4c#.bq3y94i13, http://pascalprecht.github.io/slides/angular-2-change-detection-explained. I haven't seen anything at https://angular.io/docs/ts/latest/tutorial/ though – Günter Zöchbauer Dec 02 '16 at 08:38