我在scss和cli中遇到问题:angular _nghost-fyw-1在运行时将属性添加到apps标记(组件)。同时,它向我的CSS添加了一个属性选择器,_ngcontent-fyw-1这当然是行不通的。
您是否知道如何更改/避免这种行为?
PS:它也适用于常规CSS。
我的组件.scss文件如下所示:
my-comp {
h1 {
background-color: red;
}
}
我在scss和cli中遇到问题:angular _nghost-fyw-1在运行时将属性添加到apps标记(组件)。同时,它向我的CSS添加了一个属性选择器,_ngcontent-fyw-1这当然是行不通的。
您是否知道如何更改/避免这种行为?
PS:它也适用于常规CSS。
我的组件.scss文件如下所示:
my-comp {
h1 {
background-color: red;
}
}
更新
这是::ng-deep因为一段时间。
另请参见以下注释。
原版的
您没有提供太多细节,您无法在其中添加样式以及使用选择器定位哪些元素。
如果您希望样式跨越元素边界,则“官方”方式是使用>>>like
:host >>> h1 {
background-color: red;
}
:host 定位到当前元素。>>>(或/deep/)使Angular忽略_nghost-xxx用于组件样式封装仿真的属性。
:: ng-deep对我有用,添加到app.component.scss中:
该文档(https://angular.io/guide/component-styles)表示:
Use it, with precaution...