I have followed the official guide and created a app-theme.scss
with the following content:
@import '~@angular/material/theming';
@include mat-core();
$candy-app-primary: mat-palette($mat-indigo);
$candy-app-accent: mat-palette($mat-pink, 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);
Content of styles.css
:
@import './app-theme.scss';
However, I always get the following error during compilation: Module not found: Error: Can't resolve '@angular/material/theming'
. What must I do to make it work?
Solved:
The Angular Material 2 documentation assumes you are using sass style-sheets by default. This is never clearly communicated or explained. The steps listed below can be used to resolve this issue.
styles.css
to styles.scss
and set its content to @import './app-theme';
angular-cli.json
, change styles: ["styles.css"]
to styles: ["styles.scss"]
In Angular 6+
, you simply need to install angular-material
like
ng add @angular/material
What this command does? well see here
angular material
, cdk
, animations
app.module.ts
material-icons'
reference to the index.html
angular.json
(if theme does not work, import it in styles.css/styles.scss
as described below)but in previous versions, you were doing these steps manually
Using Angular5+
, one or both import
methods will work for you
@import "@angular/material/prebuilt-themes/indigo-pink.css";
@import "~@angular/material/prebuilt-themes/indigo-pink.css"; // in official docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With