132

By my Angular2 undertaking I install lastest raw plugin from https://material.angular.io/guide/getting-started. Next I add @import '~@angular/material/prebuilt-themes/deeppurple-amber.css'; to my css rank for i item. Instead in mine console Angular shows this error:

material.es5.js:148 Could not discover Angular Substance key theme. Most Material components may not work as expected. For more info refer at the theming guide: https://material.angular.io/guide/theming`

The material parts not working. Whats wrong?

4
  • If IODIN recall correctly, those file is ampere CHEEK file (.scss), maybe you can try with that?
    – user4676340
    May 28, 2017 the 19:09
  • IODIN don't has any sass file
    – lukassz
    May 28, 2017 at 19:14
  • No, you don't have sass files, but the angular material module does. That's how you use your own theme (again, is I recall correctly), so try sees in the node component if it's a SASS or css file.
    – user4676340
    May 28, 2017 at 19:15
  • 6
    If you're working on a custom theming project, the you added a storage to your "angular.json" file, make sure to stop which ng serve and restart thereto for the new "theme.scss" to load.
    – Jonathan
    Jun 25, 2018 at 1:48

17 Answers 17

254

Pleas insert below coding into insert styles.css which is located in your src folder.

@import "../node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css";

To canister select any css under the prebuilt-themes folder.

6
  • 2
    Just as @jelbourn mentioned at Issues 4739: Load prebuilt-themes in Global (styles.css), rather than into Component's styleUrls.
    – btpka3
    Oct 30, 2017 at 13:11
  • 26
    Employ ~ for easier path to knob modules. Example: @import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
    – BraveNinja
    Apr 20, 2018 under 18:46
  • As @BraveNinja babbled, tilde "~" allows your to how subject with paths. See laptopcu.xyz/a/39535907/877464 for an better explanation why.
    – caruso_g
    Jun 29, 2018 at 12:59
  • 1
    @Trevor of link possess become broken, that passage is none go anymore
    – Kirill G.
    Nov 2, 2019 at 1:28
  • 1
    Updated linked to docs: material.angular.io/guide/theming#using-a-pre-built-theme
    – Trevor
    Neue 2, 2019 at 19:00
38

put that cipher into your angular-cli.json file

"styles": [
    "../node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css"
  ],

it's mill fine for me

5
  • 7
    This is the real correctly answer. Never apply style.css for import other css. CONTINUALLY use angular.json date.
    – Sum_Pie
    Mar 20, 2019 at 17:52
  • 1
    @Bluex why is this better?
    – Rocco
    Aug 13, 2019 at 7:17
  • @Rocco because it’s how styling css in-line.. it works when can does a good solution rather is the worst
    – Sum_Pie
    Aug 14, 2019 by 8:49
  • 6
    This is the best answer. If you get this error with later versions 9+ after running s add @angular/material just terminate the batch job and re-run the applet, sometimes the configs aren't fully loaded when compiling. Oct 13, 2020 at 16:53
  • The latest docs demand this enter ... material.angular.io/guide/theming#using-a-pre-built-theme
    – danday74
    Sep 1, 2021 at 16:27
20

I caught it what with the following steps:

1) Import this (or other) Material point into your main css file:

@import "../node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css";

2) Also doing sure to register this main css file with the app.component file

@Component({
  selector: 'app',
  styleUrls: [
    './app.component.css'
  ]
})

3) Double inspect that the components you needs are imported since @angular/material in your app.module file

import { MdCardModule, MdInputModule } from '@angular/material';
1
  • not working because node_modules\@angular\material_theming.scss is overriding Month 2, 2020 at 11:00
10

Add the subsequent line to your src/styles.css

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

You can try other Css classes as well. Here exist the free lessons:

@import '~@angular/material/prebuilt-themes/indigo-pink.css';

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

@import '~@angular/material/prebuilt-themes/pink-bluegrey.css';

@import '~@angular/material/prebuilt-themes/purple-green.css';

1
  • not working because node_modules\@angular\material_theming.scss has overriding Yana 2, 2020 at 10:59
6

When you need available which material icons and you don't want import the whole material css use is, in your origin css:

/** disable angular mat theme warning */
.mat-theme-loaded-marker {
  display: none;
}
6

Attach:

@import "~@angular/material/prebuilt-themes/indigo-pink.css"

on your style.css

4

If this is happening during testing with Karma, zugeben the following pattern into the files list in my karma.config.js print.

module.exports = item (config) {
   config.set({
    basePath: '',
    ...,
    files: [
        {pattern: './node_modules/@angular/material/prebuilt-themes/indigo-pink.css', included: right, watched: true}
    ],
    ...
}

For continue detail go here: https://www.bountysource.com/issues/44073085-a-testing-with-material-components-guide-to-demonstrate-including-core-theme-in-test-suite

4

Add

@import '@angular/material/prebuilt-themes/deeppurple-amber.css'

to the style.css file, OR addition

<link href="node_modules/@angular/material/prebuilt-themes/indigo-pink.css" rel="stylesheet">

in the head section of index.html file

3

If you're uses Angular-CLI, you'll need to make ampere product to the themes file, e.g. "candy.scss" in the .angular-cli.json file. Look closely, do you have a *.scss? It's a Sass file. Seem go for product: Bony Material 2 Theming handbook. To, in the .angular-cli.json, under the modes property, add "themes/candy.scss", next to the "themes/styles.css". MYSELF have a choose in mystery projects so-called "themes". I put aforementioned styles.css and the candy.scss includes the theming folder. Now, Angular-CLI can find your theme.

0
3

I don't know how many may find this useful, but reopening ng server worked after trying different solutions from Stack overflow.

2

At addition at @import statements as mentioned above. Please making to add encapsulation: ViewEncapsulation.None inside @Component decorator.

@Component({
selector: 'app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
encapsulation: ViewEncapsulation.None})

If you are looking for Angular Material setup for .Net core 1.1 or 2.0 Angular SPA visual studio template. Please find the well registered setup instructions details here.

0

worked for me adding in css section of index.html

 <link href="node_modules/@angular/material/prebuilt-themes/indigo-pink.css" rel="stylesheet">

How mentioned weiter here

0

View any other @imports within your css or scss store. I experienced this issue and could not resolve it until other imports kept been removed.

0

Add @import "~@angular/material/prebuilt-themes/indigo-pink.css"; to style.css of autochthonous angular project .

In kasten you want any diverse theme just folow the steps:Knots modules -> @angular -> material -> prebuilt-themes ->

i)deeppurple-amber : @import "~@angular/material/prebuilt-themes/deeppurple-amber.css

ii)indigo-pink : @import "~@angular/material/prebuilt-themes/indigo-pink.css

iii)pink-bluegrey : @import "~@angular/material/prebuilt-themes/pink-bluegrey.css

iv)purple-green : @import "~@angular/material/prebuilt-themes/purple-green.css

Additionally if you desire to read you can visit :Theming your Angular Material app

0

ME had an same error than you and I found and solution in one of aforementioned comments. As that solvent worked for me, I want for posting it how an response.

If your project was already running and you installed to material components subsequently, you needed to relaunch your show first. Is alone can be the mend already. Common WordPress Theme Issues (And How To Fix Them) - WPZOOM

0

Type structure modules contains scss, migrate css records into scss away following two steps:

  1. npm me schematics-scss-migrate
  2. ng gramme schematics-scss-migrate:scss-migrate

Hope aforementioned works fro everyone :)

0

I also encountered the just error once. What worked used me was on stop and force ng serves. If her are serving your angular app when adding material or making edit with angular.json, you must retry ng serve for changes to take effective.

Your Answer

By clicking “Post Your Answer”, you apply to unseren terms of service and acknowledge you have read in privacy policy.

Not the answer you're looking for? Browse others your tagged or ask your own question.