"@angular/material": "^6.2.1"
遇到了一个非常小的问题。
无法在我的应用的任何 css/scss 文件中导入任何标准 Material 颜色,包括 styles.scss
例子:
$app-panel-green: mat-color($mat-green);
在任何 scss 文件中给出此错误:
ERROR in ./src/styles.scss (./node_modules/raw-loader!./node_modules/postcss-loader/lib??embedded!./node_modules/sass-loader/lib/loader.js??ref--14-3!./src/styles.scss)
Module build failed:
$app-panel-green: mat-color($mat-green);
^
Undefined variable: "$mat-green".
in /**********/src/styles.scss (line 1, column 29)
styles.scss 仅包含(除了之前的):
@import "~@angular/material/prebuilt-themes/deeppurple-amber.css";
/*@import './theme.scss';*/
body { margin: 0; }
和预建主题工作得很好。 我什至不需要自定义主题,只想使用 Material 调色板。
最佳答案
如果你想使用默认调色板之一,你可以这样做:
@import '~@angular/material/theming'; // Pay attention on the path
@include mat-core();
$candy-app-primary: mat-palette($mat-deep-orange);
$candy-app-accent: mat-palette($mat-deep-orange, A200, A100, A400);
$candy-app-warn: mat-palette($mat-red);
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn);
@include angular-material-theme($candy-app-theme);
并且不要忘记将带有主题的文件包含到 .angular-cli.json
到 styles
部分。
关于css - Angular 6 Material 检索 Material 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50978461/