Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access dom element which is present under the shadow root element in Angular

<div>

<external-component>

#shadow-root

<div class="test">

<button value="submit"></button>

</div>

</external-component>

</div>

Want to access submit button. I have tried using ElementRef I am not able to access the element, because it's present under shadowDom. If any one can help me about this.

like image 680
user3273751 Avatar asked Aug 30 '25 17:08

user3273751


1 Answers

You can query like below:

constructor(ele: ElementRef){}

//Inside your function
const shadowRoot: DocumentFragment = this.ele.nativeElement.shadowRoot;
const Button = shadowRoot.querySelector('button');  
like image 174
Thalaivar Avatar answered Sep 02 '25 15:09

Thalaivar