1
votes

I read many articles about change detection but didn't get clear picture how does it work and renders view. Like in react we have virtual dom and diff algorithm which renders only part of UI that has been changed by creating dom patch so similarly how does angular know which part of UI needs to be changed.

How does changes detection decide what change will be rendered/replaced in view?

1

1 Answers

3
votes

Each component has an associated change detector object that Angular creates at runtime. The change detector object tracks all of the template bindings. When change detection runs, by default, it dirty checks each template binding in each change detector object – i.e., it compares the previous value with the current value. If a change is detected, the new value is propagated to the DOM. So if there was only one change, only one part of the DOM is updated. The entire view is not re-rendered if a change is found... only the part that changed is affected.

My longer answer: https://stackoverflow.com/a/34570122/215945