简体   繁体   English

Angular 7-用角度样式创建具有隔离范围的组件的背后机制是什么?

[英]Angular 7 -what is mechanism behind creating components with isolated scope with styles in angular?

In angular 7 - does core library using shadow dom element to handle isolated scope. 在angular 7中-核心库是否使用shadow dom元素来处理孤立的范围。 what is scene behind the creating components in angular 7 and how isolated scope its working ? 在angular 7中创建组件背后的场景是什么?如何隔离其工作范围?

can anyone please help me to understand this ? 谁能帮我理解这一点?

As per the document of angular, DOM encapsulation is used for component-specific style inject. 根据有关角度的文档,DOM封装用于特定于组件的样式注入。

This seems to be the key feature like creating a pseudo element and attaching the styles in the name of it. 这似乎是关键功能,例如创建伪元素并在其名称中附加样式。

MDN-Docs MDN-文档

Angular-Docs 角文档

Update 更新

Found this in angular's official repo: style_compiler 在angular的官方仓库中找到了这个: style_compiler

need to study deeply though! 需要深入学习!

In Angular default view Encapsulation technique is emulated , which is provided by encapsualation: viewEncapsulation.Emulated , you don't have to explicitly define this. 在角默认视图封装技术emulated ,这是由提供encapsualation: viewEncapsulation.Emulated ,你不必明确定义此。 This emulate Native scoping of styles by adding an attribute containing surrogate id to the Host Element. 通过向主机元素添加包含替代ID的属性,可以模拟样式的Native作用域。

If you are using encapsualation: viewEncapsulation.None , this doesn't provide any template or style encapsulation, whatever the styles you define, will be applied globally. 如果您使用encapsualation: viewEncapsulation.None ,则此方法不提供任何模板或样式封装,无论您定义的样式如何,都会全局应用。

If you are using encapsualation: viewEncapsulation.Native this will use the native Shadow DOM technique, but all the modern browsers does not support this. 如果您使用的是encapsualation: viewEncapsulation.Native则将使用本机的Shadow DOM技术,但所有现代浏览器均不支持此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM