angular - styleUrls 在 Angular 2 中不起作用

标签 angular systemjs angular2-template

我将 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 永远不会加载(也不会返回任何错误)。

enter image description here



工具版本:

~ 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/

相关文章:

Angular2 在选择更改时显示元素

javascript - 字符串到数字的转换不起作用

javascript - 如何在 Angular 上使用 formatDate 格式化日期

javascript - 如何获取 *ngFor 循环唯一记录

Angular 6 - 为什么生产版本中缺少 Bearer Token? (在开发构建中工作正常)

typescript - Angular2 + webpack Uncaught ReferenceError : System is not defined

angular - 使用 outDir 引用 TypeScript 编译文件的正确方法

javascript - 如何使用单独的添加按钮在 IONIC2/Angular2 表单中添加嵌套字段

angular - 剑道 UI Angular : (SystemJS) Unexpected token <

Angular2 将纯文本转换为 url( anchor 链接)的方法