【发布时间】:2018-11-03 07:01:20
【问题描述】:
我有一个示例存储库 https://github.com/collinstevens/angular-encapsulation,它演示了我的问题。
共有三个组件:EmulatedComponent、NativeComponent 和 ShadowDomComponent,它们分别使用 ViewEncapsulation.Emulated、ViewEncapsulation.Native 和 ViewEncapsulation.ShadowDom。
EmulatedComponent 的样式被复制到 <head> 中,如 https://angular.io/guide/component-styles 中所述,但也被复制到每个 #shadow-root 中,我想知道为什么,以及如果可能的话如何防止这种情况发生。
emulated.component.scss
div {
width: 50px;
height: 50px;
background-color: black;
display: inline-block;
}
native.component.scss
div {
width: 50px;
height: 50px;
background-color: red;
display: inline-block;
}
shadow-dom.component.scss
div {
width: 50px;
height: 50px;
background-color: yellow;
display: inline-block;
}
【问题讨论】:
标签: angular web-component shadow-dom