簡體   English   中英

使用NG2 Native View Encapsulation時,如何訪問shadow-dom內的ElementRef

[英]How do I access the ElementRef inside shadow-dom when using NG2 Native View Encapsulation

我有以下的plunker

我遇到的問題是當我打開本機視圖封裝時,我無法再訪問內部DOM(按設計)。 我的問題是,Angular 2是否提供了一種從組件訪問陰影dom中的DOM的方法。

// Shows 1  
platformBrowserDynamic().bootstrapModule(AppModule)
// Shows 0
// platformBrowserDynamic().bootstrapModule(AppModule, {defaultEncapsulation: ViewEncapsulation.Native}) 

與Angular2無關。 您可以使用shadowRoot屬性搜索Shadow DOM內的元素。

const shadowRoot: DocumentFragment = this.element.nativeElement.shadowRoot;
this.count = shadowRoot.children.length;

或者使用ViewChild/ViewChildren ContentChild/ContentChildren來獲取對ElementRef引用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM