2016-09-14 112 views
2

我願意使用一個通用的CSS,即我的所有應用程序模塊的根CSS。這可以通過在所有組件中單獨添加css路徑到styleUrls標籤來實現。有沒有其他的方法,比如在NgModule級別包含css?在所有模塊中使用常見的CSS,Angular 2 RC6

+1

爲什麼不能在您的index.html頭將它添加這應該工作 –

+0

我希望模塊明智,應用程序相當大,每個模塊都有自己的通用設計元素。 –

回答

1

如果將樣式添加到index.html頁面,它們將應用於所有組件,但未應用視圖封裝仿真。

除此之外,我不認爲Angular2本身提供任何東西。

+0

如果我想要模塊明智的通用CSS呢? –

+0

我很確定Angular2沒有提供任何東西。也許一些構建工具可以將樣式添加到組件的styleUrls中(而不是我的專業領域)。 –

+0

使用SASS和進口預處理器怎麼樣? –

1

今天我想知道這一點。沒有模塊化CSS的功能,所以我最終使用了Sass導入來實現我需要做的事情。

請注意,雖然它是重複性的,但它比具有應用程序範圍的CSS更好,它勝過封裝的目的。

給出下面的文件結構:

my-component/ 
├──first/ 
│ ├──first.component.ts  * first component 
│ ├──first.component.scss * first component's SCSS 
│ └──...     * first component's module, html etc. 
│ 
├──second/ 
│ ├──second.component.ts * second component 
│ ├──second.component.scss * second component's SCSS 
│ └──...     * second component's module, html etc. 
│ 
├──my-component.module.ts  * my component's module 
├──my-component.routes.ts  * my component's routes 
└──_shared.scss    * the shared partial SCSS 

我導入_shared部分進入我first.component.scsssecond.component.scss,像這樣:

@import '../shared'; 
相關問題