Angular 2 Material 主题指SCSS中的颜色
Angular 2 Material theme refer to color in SCSS
我用官方guide创建了自定义主题。
@import '../node_modules/@angular/material/core/theming/_all-theme';
@include mat-core();
$primary: mat-palette($mat-teal);
$accent: mat-palette($mat-deep-orange);
$warn: mat-palette($mat-amber);
$theme: mat-light-theme($primary, $accent, $warn);
@include angular-material-theme($theme);
它确实有效。
我可以用 $primary
设置 md-toolbar
或 md-button
的颜色。
但是我无法在组件的 SCSS 中访问颜色变量。
:host {
.mat-grid-tile-header {
background-color: $primary;
}
}
Webstorm 中的错误:
"Element 'primary' is resolved only by name without using of explicit imports"
构建失败后报错:
"Undefined variable"
好吧,我不知何故必须导入它。但是我不明白。
我试过导入主题:
@import "../../../theme.scss";
:host {
.mat-grid-tile-header {
background-color: $primary;
}
}
Webstorm 中的错误已经消失,但构建后出现新错误:
Module build failed:
undefined
^
(50: #e0f2f1, 100: #b2dfdb, 200: #80cbc4, 300: #4db6ac, 400: #26a69a, 500: #009688, 600: #00897b, 700: #00796b, 800: #00695c, 900: #004d40, A100: #a7ffeb, A200: #64ffda, A400: #1de9b6, A700: #00bfa5, contrast: (50: rgba(0, 0, 0, 0.87), 100: rgba(0, 0, 0, 0.87), 200: rgba(0, 0, 0, 0.87), 300: rgba(0, 0, 0, 0.87), 400: rgba(0, 0, 0, 0.87), 500: white, 600: white, 700: white, 800: rgba(255, 255, 255, 0.87), 900: rgba(255, 255, 255, 0.87), A100: rgba(0, 0, 0, 0.87), A200: rgba(0, 0, 0, 0.87), A400: rgba(0, 0, 0, 0.87), A700: rgba(0, 0, 0, 0.87)), default: #009688, lighter: #b2dfdb, darker: #00796b, default-contrast: white, lighter-contrast: rgba(0, 0, 0, 0.87), darker-contrast: white, "50-contrast": rgba(0, 0, 0, 0.87), "100-contrast": rgba(0, 0, 0, 0.87), "200-contrast": rgba(0, 0, 0, 0.87), "300-contrast": rgba(0, 0, 0, 0.87), "400-contrast": rgba(0, 0, 0, 0.87), "500-contrast": white, "600-contrast": white, "700-contrast": white, "800-contrast": rgba(255, 255, 255, 0.87), "900-contrast": rgba(255, 255, 255, 0.87), "A100-contrast": rgba(0, 0, 0, 0.87), "A200-contrast": rgba(0, 0, 0, 0.87), "A400-contrast": rgba(0, 0, 0, 0.87), "A700-contrast": rgba(0, 0, 0, 0.87), "contrast-contrast": null) isn't a valid CSS value.
有人知道如何解决这个问题吗?
提前致谢!
您需要使用 @angular/material/core/theming/_theming.scss
中的 mat-color($primary)
函数。这包含调色板和 returns 颜色。
我用官方guide创建了自定义主题。
@import '../node_modules/@angular/material/core/theming/_all-theme';
@include mat-core();
$primary: mat-palette($mat-teal);
$accent: mat-palette($mat-deep-orange);
$warn: mat-palette($mat-amber);
$theme: mat-light-theme($primary, $accent, $warn);
@include angular-material-theme($theme);
它确实有效。
我可以用 $primary
设置 md-toolbar
或 md-button
的颜色。
但是我无法在组件的 SCSS 中访问颜色变量。
:host {
.mat-grid-tile-header {
background-color: $primary;
}
}
Webstorm 中的错误:
"Element 'primary' is resolved only by name without using of explicit imports"
构建失败后报错: "Undefined variable"
好吧,我不知何故必须导入它。但是我不明白。
我试过导入主题:
@import "../../../theme.scss";
:host {
.mat-grid-tile-header {
background-color: $primary;
}
}
Webstorm 中的错误已经消失,但构建后出现新错误:
Module build failed:
undefined
^
(50: #e0f2f1, 100: #b2dfdb, 200: #80cbc4, 300: #4db6ac, 400: #26a69a, 500: #009688, 600: #00897b, 700: #00796b, 800: #00695c, 900: #004d40, A100: #a7ffeb, A200: #64ffda, A400: #1de9b6, A700: #00bfa5, contrast: (50: rgba(0, 0, 0, 0.87), 100: rgba(0, 0, 0, 0.87), 200: rgba(0, 0, 0, 0.87), 300: rgba(0, 0, 0, 0.87), 400: rgba(0, 0, 0, 0.87), 500: white, 600: white, 700: white, 800: rgba(255, 255, 255, 0.87), 900: rgba(255, 255, 255, 0.87), A100: rgba(0, 0, 0, 0.87), A200: rgba(0, 0, 0, 0.87), A400: rgba(0, 0, 0, 0.87), A700: rgba(0, 0, 0, 0.87)), default: #009688, lighter: #b2dfdb, darker: #00796b, default-contrast: white, lighter-contrast: rgba(0, 0, 0, 0.87), darker-contrast: white, "50-contrast": rgba(0, 0, 0, 0.87), "100-contrast": rgba(0, 0, 0, 0.87), "200-contrast": rgba(0, 0, 0, 0.87), "300-contrast": rgba(0, 0, 0, 0.87), "400-contrast": rgba(0, 0, 0, 0.87), "500-contrast": white, "600-contrast": white, "700-contrast": white, "800-contrast": rgba(255, 255, 255, 0.87), "900-contrast": rgba(255, 255, 255, 0.87), "A100-contrast": rgba(0, 0, 0, 0.87), "A200-contrast": rgba(0, 0, 0, 0.87), "A400-contrast": rgba(0, 0, 0, 0.87), "A700-contrast": rgba(0, 0, 0, 0.87), "contrast-contrast": null) isn't a valid CSS value.
有人知道如何解决这个问题吗? 提前致谢!
您需要使用 @angular/material/core/theming/_theming.scss
中的 mat-color($primary)
函数。这包含调色板和 returns 颜色。