2017-10-05 33 views
1

我使用的是Angular 4,我想使用cssscript中的circle.css。 我從鏈接下載文件,把circle.css我的東西部件文件內,但是當我在something.component.html使用
<link rel="stylesheet" href="circle.css">Angular 4在文檔頭部加載circle.css

我得到錯誤:

zone.js:654 Unhandled Promise rejection: Failed to load circle.css ; Zone: ; Task: Promise.then ; Value: Failed to load circle.css undefined* Which are the correct steps I need to follow to use the css file circle.css in my component??

+1

你把它放在index.html的''裏嗎? – Phix

回答

2

我不知道你的架構什麼,但,假設你使用角CLI和你寫的ng generate component testComponent --module app命令

現在應該把

  • 測試component.component.ts
  • 測試 - :檢測成分文件夾下的項目中的一些文件component.component.html
  • 測試component.component.css
  • 測試component.component.spec.ts

文件:測試component.component.ts

import { Component, OnInit } from '@angular/core'; 

@Component({ 
    selector: 'app-test-component', 
    templateUrl: './test-component.component.html', 
    styleUrls: ['./test-component.component.css'] 
}) 
export class TestComponentComponent implements OnInit { 

    constructor() { } 

    ngOnInit() { 
    } 

} 

這樣你就可以在「test-component」文件夾中將你的目標導入circle.css文件並添加到styleUrls組件列表中styleUrls: ['./test-component.component.css','./circle.css']

希望它有幫助

1

你必須使用該文件的相對路徑,Webpack會考慮如何解析你的絕對路徑。 如果該文件存在於同一個文件夾中,則嘗試使用./circle.css代替circle.css,如果它代替樣式文件夾,則可以編寫../styles/circle.css