我将 Angular 2 与 SystemJS 结合使用,并尝试向组件添加样式表。
由于我使用的是 SystemJS I can't use relative path截至目前,我对组件的模板 url 和样式 url 使用了绝对路径。
然而,内联样式工作正常(即 styles: ['h1 {font-size: 12px; }']
)
组件看起来像这样:
@Component({
selector: 'dashboard',
templateUrl: '/app/components/dashboard/dashboard.html',
styleUrls: ['/app/components/dashboard/dashboard.css']
})
样式表 dashboard.css
永远不会加载(也不会返回任何错误)。
工具版本:
~ angular 2: 2.0.0-beta.6
~ systemjs: 0.19.20
~ typescript :1.8.0
最佳答案
您只需删除 styleUrls 路径开头的斜杠,如下所示:
@Component({
selector: 'dashboard',
templateUrl: '/app/components/dashboard/dashboard.html',
styleUrls: ['app/components/dashboard/dashboard.css']
})
关于angular - styleUrls 在 Angular 2 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36207900/