【发布时间】:2018-05-09 21:54:57
【问题描述】:
我一直在关注有关如何创建自定义主题的角度/材料文档,关注其他博客,并检查了各种堆栈溢出类似问题,但似乎无法使其正常工作。我有以下 styles.css、angular-cli.json、theme.scss 和另一个 sass 文件,其中我的主题颜色来自 super-styles.sass。
styles.css
...
@import 'assets/styles/theme.scss';
...
angular-cli.json
...
"styles": [
"styles.css",
"src/assets/styles/theme.scss"
],
...
主题.scss
@import '~@angular/material/theming';
@import "super-styles";
// Plus imports for other components in your app.
// Include the common styles for Angular Material. We include this here so that you only
// have to load a single css file for Angular Material in your app.
// Be sure that you only ever include this mixin once!
@include mat-core()
// Define the palettes for your theme using the Material Design palettes available in palette.scss
// (imported above). For each palette, you can optionally specify a default, lighter, and darker
// hue.
$candy-app-primary: mat-palette($darkblue, A400);
$candy-app-accent: mat-palette($orange, A400);
// The warn palette is optional (defaults to red).
$candy-app-warn: mat-palette($alert);
// Create the theme object (a Sass map containing all of the palettes).
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn);
// Include theme styles for core and each component used in your app.
// Alternatively, you can import and @include the theme mixins for each component
// that you are using.
@include angular-material-theme($candy-app-theme);
超级样式.sass
...
$darkblue: #7faedd
$mediumblue: #85ceef
$lightblue: #c5e8f1
$yellow: #f4ef5f
$alert: #f37652
$orange: #fbb03c
...
根据教程,我觉得这应该可以工作,但是 angular 无法编译并且出现错误。
错误 ./node_modules/css-loader?{"sourceMap":false,"importLoaders":1}!./node_modules/postcss-loader?{"ident":"postcss"}!./src/assets/styles/theme. scss 模块构建失败:未知单词 (23:1)
21 | $candy-app-theme: mat-light-theme($candy-app-primary, $糖果应用程序口音,$糖果应用程序警告); 22 |
23 | // 包括应用程序中使用的核心和每个组件的主题样式。 | ^ 24 | // 或者,您可以为每个组件导入和@include 主题混合 25 | // 你正在使用的。
任何关于如何构建自定义主题并在我的 Angular 应用程序中使用它的帮助都会非常有帮助。谢谢!
【问题讨论】:
-
我前段时间也遇到过同样的问题,如果我没记错你不需要将
theme.scss导入style.css
标签: angular material-design angular-material