实际上我有一个样式表: <link href="../node_modules/@angular/material/core/theming/prebuilt/indigo-pink.css" rel="stylesheet">
该文件存在,Webstorm也在目录中看到该文件,但Angular2无法加载它 .
错误:GET http:// localhost:4200/node_modules/@angular/material/core/theming/prebuilt/indigo-pink.css
How to make Angular2 load that file? 感谢您提供更多信息 .
根看起来像:
- 主文件夹
--node_modules
- -东西
--src
--- index.html的
--- styles.css的
EDIT 在 mithunvp.com/angular-material-2-angular-cli-webpack/
上有一个提示可供使用
@import'~https://fonts.googleapis.com/icon?family = Material Icons'; @import'~@angular/material/core/theming/prebuilt/deeppurple-amber.css';
打开预建主题 . 但是再次,即使它被粘贴在 styles.css
内部,它也会返回它无法找到的错误 . 它甚至找不到材料图标,这是一个链接......
3 回答
您不应该尝试加载这样的css,甚至可以使用sccs源文件 .
使用
angular-cli
,我可以想象你有文件src/styles.scss
或.less
对吗? (除非你决定使用纯css?!) .所以,如果你正在使用sass,请在
src/styles.scss
中放入:@import '~@angular/material/core/theming/prebuilt/indigo-pink.css';
另外,我可以想象你所看到的卡拉's demo with angular-material, I' d建议你去看看:https://www.youtube.com/watch?v=0q9FOeEELPY
要修复问题,请从index.html内联 styles.css 并将其添加到angular-cli.json下的样式数组中
希望 . 它会工作
您应该使用以下语句
代替
在
styles.css
内 .