问题描述
我实际上在Angular2中是新手,并且继承了Angular 2前端的项目.在控制台上切换到新的Angular 4.0之后,我看到错误:
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找不到Angular Material核心主题.大多数Material组件可能无法正常工作.有关更多信息,请参考主题指南: https://material.angular.io/guide/theming "
"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"
mdb.min.css在app/assets/css文件夹中. package.json中的规范显示以下内容:
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": "*"
如何解决该错误?
推荐答案
您必须将主题导入到全局css或sass文件中:
You have to import a theme into your global css or sass file:
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
或将其包含在您的index.html
文件中:
or alternatively include it in your index.html
file:
<link href="node_modules/@angular/material/prebuilt-themes/indigo-pink.css" rel="stylesheet">
就像已经提到的主题文档一样,Angular Material提供了以下预先构建的主题:
As in the theming documentation already mentioned Angular Material provides the following pre-built themes:
- deeppurple-amber.css
- indigo-pink.css
- pink-bluegrey.css
- purple-green.css
您必须包括以下主题之一,或者创建自己的自定义主题.
You have to include one of these themes or you create your own custom theme.
这篇关于如何修复Angular 2中的错误“找不到Angular Material核心主题"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!