Change Detection

Change Detector by Vovka is licensed under Public Domain  (https://pixabay.com/en/coins-handful-russia-ruble-kopek-650779/)
Figure: Change Detector by Vovka is licensed under Public Domain (https://pixabay.com/en/coins-handful-russia-ruble-kopek-650779/)

Change detection is the process that allows Angular to keep our views in sync with our models.

Change detection has changed in a big way between the old version of Angular and the new one. In Angular 1, the framework kept a long list of watchers (one for every property bound to our templates) that needed to be checked every-time a digest cycle was started. This was called dirty checking and it was the only change detection mechanism available.

Because by default Angular 1 implemented two way data binding, the flow of changes was pretty much chaotic, models were able to change directives, directives were able to change models, directives were able to change other directives and models were able to change other models.

In Angular 2, the flow of information is unidirectional, even when using ngModel to implement two way data binding, which is only syntactic sugar on top of the unidirectional flow. In this new version of the framework, our code is responsible for updating the models. Angular is only responsible for reflecting those changes in the components and the DOM by means of the selected change detection strategy.

results matching ""

    No results matching ""