如何修复 Angular 2 中“找不到 Angular Material 核心主题"的错误? [英] How to fix the error “Could not find Angular Material core theme” in Angular 2?

查看:40
本文介绍了如何修复 Angular 2 中“找不到 Angular Material 核心主题"的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎是 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
  • 紫色-绿色.css

您必须包含这些主题之一,或者您创建自己的自定义主题.

You have to include one of these themes or you create your own custom theme.

这篇关于如何修复 Angular 2 中“找不到 Angular Material 核心主题"的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆