[英]How do I access the ElementRef inside shadow-dom when using NG2 Native View Encapsulation
我遇到的問題是當我打開本機視圖封裝時,我無法再訪問內部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.