如何禁用 ViewEncapsulation.None 的效果?例如,我的一个组件 (firstComponent) 定义了一个带有一些属性的 css 类。有 secondComponent 使用相同的 css 类。我希望我的“secondComponent”对第一个组件样式表定义的属性使用不同的特定值。我怎样才能做到这一点?
注意:我用不同的值在“secondComponent”中重新定义了同一个类,保持 secondComponent 默认的 viewEncapsulation。它对我不起作用。
FirstComponent:
@Component({
moduleId: module.id,
selector: "FirstComponent",
templateUrl: 'FirstComponent.component.html',
styleUrls: ['FirstComponent.component.css'],
encapsulation: ViewEncapsulation.None
})
FirstComponent.component.css
.ui-tree .ui-tree-container {
background-color: #252525;
color: white;
}
Second Component:
@Component({
moduleId: module.id,
selector: "SecondComponent",
templateUrl: 'SecondComponent.component.html',
styleUrls: ['SecondComponent.component.css'],
})
SecondComponent.Component.css
.ui-tree .ui-tree-container {
background-color: white;
color: black;
}
我在内部使用 .ui-tree-container 的两个组件中都创建了 p-tree。我希望我的 secondComponent 的树的背景应该是白色的,而对于所有其他地方的树的背景应该保持黑色。