I am practically new in Angular2 and inherited the project with Angular 2 frontend. After switching to the new Angular 4.0 on console I see the error:
"compatibility.ts:221 Could not find Angular Material core theme. Most Material components may not work as expected. For more info refer to the theming guide: https://material.angular.io/guide/theming"
The mdb.min.css is in the app/assets/css folder. The specification in package.json shows the following:
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
...
"angular-bootstrap-md": "*"
How to fix the error?
Look here for information: Angular Material 2 Theming instructions. So, in the .angular-cli.json, under the styles property, add "themes/candy.scss", next to the "themes/styles.css". I have a folder in my projects called "themes". I put the styles.css and the candy.scss in the themes folder. Now, Angular-CLI can find your theme.
For existing apps, follow these steps to begin using Angular Material. You can use either the npm or yarn command-line tool to install packages. Use whichever is appropriate for your project in the examples below. A snapshot build with the latest changes from master is also available.
Whichever approach you use, be sure to import the Angular Material modules after Angular's BrowserModule, as the import order matters for NgModules. Including a theme is required to apply all of the core and theme styles to your application.
Note: @angular/animations uses the WebAnimation API that isn't supported by all browsers yet. If you want to support Material component animations in these browsers, you'll have to include a polyfill. If you don't want to add another dependency to your project, you can use the NoopAnimationsModule.
You have to import a theme into your global css or sass file:
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
or alternatively include it in your index.html
file:
<link href="node_modules/@angular/material/prebuilt-themes/indigo-pink.css" rel="stylesheet">
As in the theming documentation already mentioned Angular Material provides the following pre-built themes:
You have to include one of these themes or you create your own custom theme.
Adding @import to styles.css
doesn't work for me, adding theme to angular.json
did the trick
You can replace the default angular-material-theme with one of the above-mentioned angular-material-themes using the following ways.
You can directly include the pre-built angular-material-theme in the styles.css file.
@import '@angular/material/prebuilt-themes/deeppurple-amber.css';
Or Add the following inside the head tag of index.html file.
<link href="node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css" rel="stylesheet">
Or Update the following in angular.json file.
"styles": [
{
"input": "node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css"
},
"src/styles.css"
],
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