2017-09-07 46 views
0

我想在角度組件中使用cdn中的樣式表。樣式只能封裝在該組件內。不能使用本地封裝模式,即不支持。在角度2組件中使用cdn中的樣式表

有什麼建議嗎?

+0

歡迎來到Stack Overflow。請閱讀http://stackoverflow.com/help/how-to-ask –

+0

請爲您的問題添加更多詳細信息,例如您正在使用的構建過程,以及您已嘗試過的內容。 –

+0

@ArunVinoth - 它是一個非常好的問題,最有角度的4開發人員問。 –

回答

0

我不認爲有一種好的方法可以在組件模板中做到這一點。我會說探索ngAfterViewInit選項作爲大多數外部事物,並且一旦角部模板被比較,就放置在組件的內部週期中。

@Component({selector: 'my-cmp', template: `...`}) 
class MyComponent implements AfterViewInit { 
    ngAfterViewInit() { 
    // executes after the view is loaded 
    } 
} 

如果你正在使用的角度CLI您可以在您的CLI文件中配置他們,但我認爲你需要下載到您的資源路徑,並給出了路徑。我不認爲cli會採取cdn路徑。

//part of cli configuration 
    "prefix": "sd", 
    "styles": [ 
    "../node_modules/bootstrap/scss/bootstrap.scss", 
    "../node_modules/font-awesome/scss/font-awesome.scss", 
    "../node_modules/primeng/resources/primeng.min.css", 
    "../node_modules/primeng/resources/themes/omega/theme.css", 
    "../node_modules/codemirror/lib/codemirror.css", 
    "styles.scss" 
    ],