繁体   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