首页 > 解决方案 > 无法更改垫旋转器的颜色

问题描述

我知道有人问过这个问题(更改 mat-spinner 的颜色),但我想知道是否有不使用已弃用的 ::ng-deep 的解决方案?

此外,我还尝试了链接中建议的方法,但不起作用:

HTML

<mat-progress-spinner *ngIf="pending" mode="indeterminate" class="mat-spinner-color"></mat-progress-spinner>

SCSS

.mat-spinner-color::ng-deep circle{
    stroke: #FFFFFF !important;
}

提前致谢!

标签: angular-material

解决方案


::ng-deep 没有被正式弃用,并且取决于浏览器是否删除了对它的支持,per angular.io,until then意味着浏览器正式弃用它,it should be preferred以实现更广泛的兼容性。/deep/>>>

因此,我们计划放弃对 Angular 的支持(对 /deep/、>>> 和 ::ng-deep 的所有 3 个)。在此之前 ::ng-deep 应该是首选,以便与工具更广泛地兼容。

https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep


如果您的偏好是避免 ::ng-deep ,则需要将您的修改应用于项目mat-spinner的根目录styles.css

styles.css

.orange-spinner circle{
  stroke:orange !important;
}

添加类

<mat-spinner class="orange-spinner"></mat-spinner>

堆栈闪电战

https://stackblitz.com/edit/angular-czd4zq?embed=1&file=styles.css


请注意:

根据UmutEsen下面的评论,正确的解决方案是设置主题并color利用mat-spinner.

https://material.angular.io/guide/theming


推荐阅读