use*_*751 3 typescript angularjs-directive angular-material angular
<div>
<external-component>
#shadow-root
<div class="test">
<button value="submit"></button>
</div>
</external-component>
</div>
Run Code Online (Sandbox Code Playgroud)
想要访问提交按钮。我尝试使用 ElementRef 我无法访问该元素,因为它存在于 ShadowDom 下。如果有人可以帮助我解决这个问题。
您可以像下面这样查询:
constructor(ele: ElementRef){}
//Inside your function
const shadowRoot: DocumentFragment = this.ele.nativeElement.shadowRoot;
const Button = shadowRoot.querySelector('button');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6706 次 |
| 最近记录: |