如果您使用的是 angular-cli,我建议您这样做。
在您的应用文件夹中创建一个“custom-theme.scss”。
@import '~@angular/material/core/theming/all-theme';
// Plus imports for other components in your app.
// Include the base styles for Angular Material core. We include this here so that you only
// have to load a single css file for Angular Material in your app.
@include md-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.
$primary: md-palette($md-indigo);
$accent: md-palette($md-pink, A200, A100, A400);
// The warn palette is optional (defaults to red).
$warn: md-palette($md-red);
// Create the theme object (a Sass map containing all of the palettes).
$theme: md-light-theme($primary, $accent, $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($theme);
在您的 angular-cli.json 中,将自定义样式添加到样式中:
app/custom-theme.scss