简体   繁体   English

如何覆盖材料 Angular 组件 styles 中的 Sass 变量?

[英]How can I override Sass variables in Material Angular component styles?

I am searching for a whole now for result of my problem.我现在正在寻找一个整体来寻找我的问题的结果。 In my company, I must style material design for our project, and this is so awkward that there is absolutely no way to style through sass variables (I mean, not only colours and fonts).在我的公司,我必须为我们的项目设计材料设计,这太尴尬了,绝对没有办法通过 sass 变量来设置样式(我的意思是,不仅仅是颜色和字体)。 I can't override lot of styles because of this impossible encapsulations etc. My work is so slow.由于这种不可能的封装等,我无法覆盖很多 styles。我的工作太慢了。 If I could override just variables like from _button- base.scss it would be not that much frustrating... I can't use viewEncapsulation.none like in lot of suggestions.如果我可以只覆盖 _button base.scss之类的变量,那就不会那么令人沮丧了……我不能像在很多建议中那样使用viewEncapsulation.none

I don't know Sass very well so maybe I don't see the result.我不太了解 Sass 所以也许我看不到结果。 How can it be possible to not styling by variables, there are all here in material sass files.怎么可能不按变量进行样式设置,材料 sass 文件中都有。 I found only one answer like this:我只找到一个这样的答案:

.mat-button {
  @extend %mat-button-base;
}

but this doesn't work for me.但这对我不起作用。 Anyone has other solution?有人有其他解决方案吗?

You should the angular-material site: https://material.io/design/color/the-color-system.html#color-usage-and-palettes你应该 angular-material 站点: https://material.io/design/color/the-color-system.html#color-usage-and-palettes

Option 1: change the $mat-indigo, $mat-pink and $mat-red to material palettes of your choice.选项 1:将 $mat-indigo、$mat-pink 和 $mat-red 更改为您选择的材质调色板。

@import '~@angular/material/theming';
@include mat-core();

$candy-app-primary: mat-palette($mat-indigo);
$candy-app-accent:  mat-palette($mat-pink, A200, A100, A400);
$candy-app-warn:    mat-palette($mat-red);


$candy-app-theme: mat-light-theme((
  color: (
    primary: $candy-app-primary,
    accent: $candy-app-accent,
    warn: $candy-app-warn,  
  )
));


@include angular-material-theme($candy-app-theme);

Option2 : Override them by making your SCSS more specific.选项2 :通过使您的 SCSS 更具体来覆盖它们。

Option3 : Use::ng-deep to override specific components.选项3 :使用::ng-deep 覆盖特定组件。

PS You really should NOT use viewEncapsulation.none . PS你真的不应该使用viewEncapsulation.none That is the whole idea of angular which created encapsulated components.这就是创建封装组件的 angular 的全部想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM