【问题标题】:Angular 4 styleUrls file not found找不到Angular 4 styleUrls文件
【发布时间】:2017-06-20 01:22:54
【问题描述】:

我正在使用带有 Rails 5.1 的 Angular 4.1.3

我想在我的组件中使用 styleUrls,但出现错误。

这是错误。

zone.js?4c9b:643 Unhandled Promise rejection: Failed to load app.component.css ; Zone: <root> ; Task: Promise.then ; Value: Failed to load app.component.css undefined

这是我的组件。

import { Component } from '@angular/core';
import template from './app.component.html'

@Component({
  selector: 'app-root',
  template: template,
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  name = '';
}

这是我的文件结构

├── app
        app.component.css
|   ├── app.component.html
|   └── app.component.ts
|   └── app.module.ts

【问题讨论】:

    标签: javascript angular


    【解决方案1】:

    试试这个,

    @Component({
      moduleId: module.id,
      selector: 'app-root',
      template: template,
      styleUrls: ['app.component.css']
    })
    

    【讨论】:

    • ./app.component.css 有什么问题? ./app.component.html 加载正常。
    • module.id 需要指定才能为您的组件加载相关资产。这是一个完整的答案-> stackoverflow.com/questions/37178192/…
    猜你喜欢
    • 2018-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-02
    • 2017-07-15
    • 2018-04-10
    • 2018-11-16
    • 2018-10-04
    相关资源
    最近更新 更多