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
Hi! Ciao! How Are You???
Bug, feature request, or proposal:
Could not find Angular Material core theme, although all core @include mat-core(); is included. I got 6 themes, all working except the warning.
What is the expected behavior?
No warning.
What is the current behavior?
Warning.
What are the steps to reproduce?
git clone https://github.com/patrikx3/corifeus-app-web-pages.git
cd corifeus-app-web-pages
yarn install
grunt run
See.
What is the use-case or motivation for changing an existing behavior?
Themes.
Which versions of Angular, Material, OS, browsers are affected?
Current.
Is there anything else we should know?
Nope.
Yeah, I'm getting this as well.
We have a marker style that we check for on load. When are you loading your theme?
It is dynamic, based on a cookie.
but i think the mat-core is loading right away. it is in a css. so instant i think.
I can see you loading the mixins in a few places, but I couldn't find any instances of the mat-core or angular-material-theme mixins being included anywhere.
https://github.com/patrikx3/corifeus-web-material.git The styles are there.
https://github.com/patrikx3/corifeus-web-material/blob/master/src/scss/material/_all.scss
that is a componet. and i include here: https://github.com/patrikx3/corifeus-app-web-pages/blob/f734270fd15d263beb4930095a90d20b7165cb42/src/angular/layout/cory-layout.scss
Alright, then it's definitely an issue with Material checking too early. We probably can't anticipate when styles are loaded without a major performance hit, but we could add a flag to disable the warnings for advanced cases like this. What do you think @jelbourn?
Being able to disable the warning might help with #4056 too
@crisbeto what if we just delay the check for a few seconds? That way it will still be visible to developers by the time they open the dev tools but should be enough time to load styles for initial view.
We could, but that can still be race condition-ey. We can do something like a 5s delay if we really want to be safe.
I'd be okay with that as a simple workaround
It seems like the warning itself could be removed in favor of a clearer set of requirements in the documentation.
I may be missing some other reason for its existence, but it appears that the compatibility module is just checking to make sure you've put @include mat-core(); in your style. Couldn't that requirement be made more obvious (e.g., bold) in the docs, rendering the warning redundant?
Personally, the idea of tweaking timers to do css checks feels a bit hacky.
We do have info about it in the docs @Torqode, however people tend to miss it, which ends up looking like it works in some cases, but breaks once you start using the overlay-based components. I'm not sure that making it bolder will solve the issue.
This issue tied me in knots, but eventually, I realised that what Angular's own Materials tutorial doesn't tell us is that we must include this line in the "styles.css" file, to make the controls appear normally (certainly in Windows 7).
@import "../node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css";
Trying to include that file using an "include", even in the index.html file, failed miserably for me. It could never locate this .css file.. even if I manually copied it into the same folder as index.html.
@MikeInSwitzerland It works for me. Thanks.
How can I override the theme colors using scss and still include it before modules try to load and I get the Could not find Angular Material core theme error?
@crisbeto GREAT! Your documentation does describe each directive such as mat-core and angular-material-theme. I GET THAT!!
Now, where do I refer to theme.scss so that it is compiled and included in the page before receiving the error Could not find Angular Material core theme. ?
Let me explain what we need answered in this thread. Lets say I have some basic css and the material theme color instructions all contained in theme.scss. Follow me so far?
Do I put theme.scss in tsconfig? E.g.:
{
"compilerOptions": {
"styles": {
"./theme.scss"
}
}
}
NOPE! That's not going to work!
Where do I put theme.scss so that it is compiled? Maybe angular-cli.json?
{
"apps": [
{
styles: [
"./theme.scss"
]
}
]
}
NO, that doesn't work because it doesn't compile scss, it just inserts css into the head of index.html.
Error: Could not find Angular Material core theme
In my app.component.ts? https://github.com/ng-seed/universal/blob/master/src/client/app/app.component.ts
// external styles
import '../assets/sass/layout.scss';
NO! That only works with awesome-typescript-loader and webpack, doesn't work with angular-cli?
How about using encapsulation: ViewEncapsulation.None in app.component.ts?
@Component({
selector: 'bc-app',
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [TranslateService, LayoutService],
templateUrl: './app.component.html',
styleUrls: ['./theme.scss', './app.component.scss'],
encapsulation: ViewEncapsulation.None,
})
HEY THAT WORKS! Except we still get this error message even though everything looks correct.
Any ideas? Anyone? Does every theme have to start with a precompiled color in order to resolve this error? Do you start with a precompiled theme and then override the theme meaning it injects multiple themes in to your page?
What is the most up to date method for doing this and why isn't it made clear on this page? https://material.angular.io/guide/theming
@willshowell Provides a great example of a use case with linking multiple .scss files together:
https://github.com/angular/material2/issues/6063#issuecomment-318141302
I don't get it. I still get the error.
@Component({
selector: 'cory-web-material-test-layout',
templateUrl: './layout.html',
encapsulation: ViewEncapsulation.None
})
@import '@angular/material/theming';
@include mat-core();
No matter I do I get the warning, and with electron, it doesn't load the SCSS. :(
In the web it works. Ok, warning.
But, in Electron, something is fishy.