【发布时间】:2018-10-08 19:21:22
【问题描述】:
我正在尝试将自定义 Angular Material 主题中自定义调色板中的颜色用于其他一些组件。
例如一个带有 mat-toolbar 的 div 和一个带有边距的图标,应该用主背景颜色填充。
关于主题的 Angular Material 指南说:
不应将主题文件导入其他 SCSS 文件。这将导致重复的样式被写入您的 CSS 输出。
但在组件主题指南中,它说如下:
您可以使用来自@angular/material/theming 的主题函数和材质调色板变量。您可以使用 mat-color 函数从调色板中提取特定颜色。例如:
// Import theming functions
@import '~@angular/material/theming';
// Import your custom theme
@import 'src/unicorn-app-theme.scss';
// Use mat-color to extract individual colors from a palette as necessary.
// The hue can be one of the standard values (500, A400, etc.), one of the three preconfigured
// hues (default, lighter, darker), or any of the aforementioned prefixed with "-contrast".
// For example a hue of "darker-contrast" gives a light color to contrast with a "darker" hue.
// Note that quotes are needed when using a numeric hue with the "-contrast" modifier.
// Available color palettes: https://www.google.com/design/spec/style/color.html
.candy-carousel {
background-color: mat-color($candy-app-primary);
border-color: mat-color($candy-app-accent, A400);
color: mat-color($candy-app-primary, '100-contrast');
}
主题在组件中再次导入,他们从材料主题中提取颜色与功能。
我很困惑,在没有颜色输入的非角度材质组件或事件材质组件上使用颜色的正确方法是什么?
【问题讨论】:
-
你有没有得到这个问题的解决方案?
-
很遗憾没有。必须使用 css 类创建解决方法。
标签: angular sass angular-material