Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Angular update only one DOM element or all DOM element when interpolation is used

Tags:

angular

Consider that I have a child component with the following view template in Angular2 (or 4):

<div id="firstDiv">
<div id="secondDiv">
<span> {{someproperty}}</span>

<div>
</div>

And someproperty is a modified by the parent component using @input binding on the child. When the value of @input property changes, does the re-rendering of the child view happen at the div with the id of firstDiv or only at the <span> level? In other words, does the whole shown structure get refreshed or just the span or just the text in the span?

like image 926
Sean12 Avatar asked Jan 02 '26 02:01

Sean12


1 Answers

Only the text node inside the span element will be updated using the renderer. Here is the relevant code snippet from the sources:

if (checkAndUpdateBinding(view, nodeDef, bindingIndex, newValue)) {
    value = text + _addInterpolationPart(...);
    view.renderer.setValue(DOMNode, value);
}

DOMNode here is the reference to the textNode.

For more details read The mechanics of DOM updates in Angular

like image 164
Max Koretskyi Avatar answered Jan 04 '26 22:01

Max Koretskyi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!