1

I am using Angular 4.1.3 with Rails 5.1

I want use styleUrls to my component, but get error.

Here is error.

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

Here is my component.

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 = '';
}

And this is my file structure

├── app
        app.component.css
|   ├── app.component.html
|   └── app.component.ts
|   └── app.module.ts
31piy
  • 23,323
  • 6
  • 47
  • 67
zoucaitou
  • 11
  • 3

1 Answers1

0

Try this,

@Component({
  moduleId: module.id,
  selector: 'app-root',
  template: template,
  styleUrls: ['app.component.css']
})
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • 1
    what's wrong with `./app.component.css`? `./app.component.html` loads just fine. – 31piy Jun 20 '17 at 05:00
  • `module.id` needs to be specfied in order to load relative assets for your components. Here's a complete answer -> https://stackoverflow.com/questions/37178192/angular2-what-is-the-meanings-of-module-id-in-component – Alexus Jun 20 '17 at 08:46