Angular 2 Material无法加载样式

时间:2017-05-05 21:18:03

标签: css angular angular-material2

我开始使用角度材质库为Angular开发一个Web应用程序。但是在尝试导入预建主题时出现错误。为了导入它,我将<link rel="stylesheet" href="../node_modules/@angular/material/prebuilt-themes/indigo-pink.css">添加到我的index.html文件中,但是当我运行ng serve时,我无法获取该文件。

3 个答案:

答案 0 :(得分:9)

如果您使用angular-cli,请关注steps for including Angular-Material

确保您在src/styles.css

中拥有以下导入
@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
@import '~https://fonts.googleapis.com/icon?family=Material+Icons';

angular-material在他们自己的使用入门网站上建议的内容略有不同,但它对我有用。

答案 1 :(得分:2)

检查您的路径是否正确。我有同样的问题,我修复了路径: 我的是

if(typeof(width)=="undefined"){
var width = '100%';
}
if(typeof(height)=="undefined"){
var height = '100%';
}
if(typeof(p)=="undefined"){
var p = '0';
}
if(typeof(c)=="undefined"){
var c = '0';
}
if(typeof(stretching)=="undefined"){
var stretching = 'uniform';
}
document.write('<iframe allowfullscreen width="'+width+'" height="'+height+'" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="true" src="http://example.com/examplefile.php?id='+id+'&p='+p+'&c='+c+'&stretching='+stretching+'"></iframe>');

答案 2 :(得分:0)

如果找不到任何解决方案,只需再次添加棱角材料。它不会影响您的代码,但会添加CSS。不要忘记重新启动角度服务器。

ng add @angular/material
相关问题