简体   繁体   English

MEAN 应用程序:无法在 Angular 材料中找到主题

[英]MEAN app: Can't find theme in Angular material

So I just discovered Angular material.所以我刚刚发现了 Angular 材料。 I wanted to set it up, but the browser can't load the Angular material theme.我想设置它,但是浏览器无法加载 Angular 材质主题。 It gives me the following error:它给了我以下错误:

Could not find Angular Material core theme.找不到 Angular Material 核心主题。 Most Material components may not work as expected.大多数 Material 组件可能无法按预期工作。 For more info refer to the theming guide: https://material.angular.io/guide/theming有关更多信息,请参阅主题指南: https ://material.angular.io/guide/theming

And,和,

Resource interpreted as Stylesheet but transferred with MIME type text/html: " http://localhost:3200/node_modules/@angular/material/prebuilt-themes/indigo-pink.css ".资源解释为样式表但使用 MIME 类型文本/html 传输:“ http://localhost:3200/node_modules/@angular/material/prebuilt-themes/indigo-pink.css ”。

First, here is the structure of my project:首先,这是我的项目的结构:

在此处输入图像描述

As you can see I added a element with a link to the indigo-pink theme in the index.hbs file.如您所见,我在 index.hbs 文件中添加了一个元素,其中包含指向 indigo-pink 主题的链接。 Before that I tried to import the theme into my styles.css file in the public folder with在此之前,我尝试将主题导入到公用文件夹中的 styles.css 文件中

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

Both ways ended up giving me the same above error.这两种方式最终都给了我同样的上述错误。 Does someone see what I'm doing wrong?有人看到我做错了什么吗?

You definitely cannot refer to node_modules in the index.html.您绝对不能在 index.html 中引用 node_modules。 @import would be the correct way. @import 将是正确的方法。 Looks like you're using Webpack and not Angular CLI which would make this work automatically, so you need to find a Webpack plugin that handles @import and bundles the styles together, or if you have one, fix your webpack config.看起来您使用的是 Webpack 而不是 Angular CLI,它会使这项工作自动进行,因此您需要找到一个 Webpack 插件来处理 @import 并将样式捆绑在一起,或者如果您有一个,请修复您的 webpack 配置。 Try: https://github.com/webpack-contrib/css-loader尝试: https ://github.com/webpack-contrib/css-loader

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM