2016-07-07 85 views
3

已經有an answered question,它解釋了ViewEncapsulation.Emulated,ViewEncapsulation.NativeViewEncapsulation.None之間的差異。Angular 2原生視圖封裝

假設有Electron應用程序保證與本地支持shadow DOM和ViewEncapsulation.Native的Chromium版本捆綁在一起。這種情況如何從本地封裝中受益以避免模擬開銷?

另一種可能的情況是調試視圖角2的應用程序,與由於ViewEncapsulation.Emulated幫手屬性和命名空間CSS類嚴重混亂。

對於沒有指定encapsulation的所有組件,默認封裝可以全局更改爲ViewEncapsulation.Native

ViewEncapsulation.Native的其他實用設備是什麼?

回答

3

根據https://github.com/angular/angular/pull/7883這應該工作

import {CompilerConfig} from '@angular/compiler'; 

bootstrap(AppComponent, [{ 
    provide: CompilerConfig, 
    useValue: new CompilerConfig({defaultEncapsulation: ViewEncapsulation.Native}) 
}]) 

我還沒有嘗試過自己尚未雖然。

我猜想ViewEncapsulation.Native將主要是有利的,因爲只有Chrome瀏覽器的目標。似乎在其他瀏覽器發佈其影子DOM支持之前,仍然需要相當長的時間。

主要優點是Angular2不需要爲每個組件元素添加屬性,並且不需要將所有組件樣式添加到<head>了。使用脫機模板編譯時

性能不會有太大的在大多數情況下的問題與Emulated

+1

有一個語法錯誤,但否則它正在工作。謝謝。 – estus

+0

感謝您修復:)和反饋。 –