2017-05-30 58 views
1

我使用的是一個Angular 2組件,它遵循屬性,並且在Chrome桌面瀏覽器中工作正常。Angular 2 ViewEncapsulation.Native vs ViewEncapsulation.Emulated問題在鉻的iPad和鉻瀏覽器

@Component({ 
    selector: 'some-header', 
    templateUrl: './someheader.component.html', 
    styleUrls: ['./someheader.component.scss'], 
    encapsulation: ViewEncapsulation.Native 
}) 

但在我的iPad上的Chrome瀏覽器,它是給我在頁面加載以下錯誤

hostEI.createShadowRoot is undefined 

但是,當我將其更改爲

ViewEncapsulation.Emulated 

它開始在我的iPad上運行,但我的UI在桌面上打破了。

我檢查以下鏈接計算器

link

但我的問題是,我可以根據組件的裝飾一定條件下動態地添加此encapsulation屬性。

感謝

+1

[網絡組件polyfills(https://www.webcomponents.org/polyfills/)應該做的伎倆 –

+0

感謝這就是我一直在尋找:) – Rishi

回答

2

並非所有的瀏覽器不支持ShadowDom(如IE,Safari瀏覽器等),在這種情況下createShadowRoot被失敗。

你可以從下面的鏈接添加對WebComponent的polyfills輕鬆解決這個問題

https://www.webcomponents.org/polyfills/