Does Angular 2 use Shadow DOM or a Virtual DOM?

假装没事ソ 提交于 2019-12-03 06:32:32

问题


What does Angular 2 use to update the DOM. Is it Shadow DOM or Virtual DOM ? Was there any such concept in Angular 1?


回答1:


Angular2 doesn't use shadow DOM (default) nor virtual DOM.

With encapsulation: ViewEncapsulation.Emulated (default) there is no shadow DOM because style encapsulation is only emulated.

encapsulation: ViewEncapsulation.Native enables shadow DOM on browsers that support it natively or it's again emulated when the webcomponents polyfill is loaded.

Shadow DOM is also not targeting performance as virtual DOM is, but style encapsulation.

Angular2 doesn't use virtual DOM at all.

Angular2 has change detection that detects changes to the model and only updates the parts of the DOM that need to be changed according to the model changes.

For more details see also Is shadow DOM fast like Virtual DOM in React.js?




回答2:


React and Vue are using Virtual DOM and Angular use direct DOM rendering system.

It's the same thing that Angular did with version 1.x, but it is optimized and there is a surprise for you :)

It is much faster to work with JavaScript objects than with DOM, because nothing drown on screen



来源:https://stackoverflow.com/questions/39739648/does-angular-2-use-shadow-dom-or-a-virtual-dom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!