NG-NL 2016: Pascal Precht - Angular 2 Change Detection Explained

NG-NL · 36K views · 2016 · 44:26

Open on YouTube

Web developmentSoftware performance & optimizationtalkdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about how Angular 2 detects changes and how to tune re-rendering, calling it the best explanation they have found.

Recommended by 3 people across 3 different months, 2016 to 2017.

What it is

A 44-minute conference talk from NG-NL 2016 in which Pascal Precht explains how change detection works in Angular 2, covering zones, change detectors and how to optimize them with immutable inputs and OnPush. It is a conference session by an Angular core contributor.

What people said

Strong rec Tiberiu Popescu · 2016-04 · Stack Overflow · on “Does Angular 2 have re-rendering optimization?”

Angular2 is using zone.js [LINK] for onChange rendering. Usually when a change is detected, it will trigger changeDetection that component and all the children, but you also can have control to change that, to force render some things or not render when you don't like angular2 behavior. Here is a very good talk about how Angular2 change detection [this video] works : [this video] LE: Just to clarify, it will not re-render the component and all the children, it will detect and trigger changes for all of those, but will render only what is necessary.

Strong rec Santanu Biswas · 2017-01 · Stack Overflow · on “Angular 2 change detector”

Here is the link to a video on YouTube. This is the best one I have come across so far to understand ChangeDetection in Angular2 [this video]

Strong rec Melou · 2017-03 · Stack Overflow · on “Angular change detection on @Input object”

The straightforward way of executing an action everytime anObject change is by using a setter or ngOnChange (see Fals' answer). Using immutable objects witch a change detection strategy of OnPush is a way to improve change detection performance. This is not the most obvious use of change detection in Angular. For a complete explanation I suggest you read this really good article [LINK] and if you have some time (45 minutes) you can check this video by the author of the article here [this video] From there, you should have a good understanding of what's going on.