Angular ::ng-deep 不能以全局方式工作

Posted

技术标签:

【中文标题】Angular ::ng-deep 不能以全局方式工作【英文标题】:Angular ::ng-deep not working in global style 【发布时间】:2020-06-10 05:39:16 【问题描述】:

我用我插入的样式创建了一个组件

::ng-deep .input-blue.mat-focused .mat-form-field-label 
  color: #6200EE !important;

完美运行。但是,当我将此代码添加到全局样式中以在所有不工作的组件中使用它时。

【问题讨论】:

仅供参考 ::ng-deep 即将停用,请避免使用 这能回答你的问题吗? How and where to use ::ng-deep? 【参考方案1】:

全局 style.css 只是一个普通的、非 Angular 或至少非封装(这是它的全部要点)样式表。删除::ng-deep 然后离开

.input-blue.mat-focused .mat-form-field-label 
  color: #6200EE !important;

【讨论】:

以上是关于Angular ::ng-deep 不能以全局方式工作的主要内容,如果未能解决你的问题,请参考以下文章

[Angular] Use :host-context and the ::ng-deep selector to apply context-based styling

如何删除 WebStorm sass-lint 错误“未知的伪选择器 'ng-deep'”

/deep/ OR ::ng-deep 的长期替代解决方案是啥?

如何将全局样式添加到 Angular 6/7 库

将 Angular 2 (click) 属性全局添加到 CSS

Angular 6替代全局css的方式