I need to add a template reference variable inside a dynamic generated Iframe of Button element. Like this: <button #submitBtn> Submit
ngAfterViewInit() {
$('iframe').attr('id', 'IframeId');
}
// fire this function when main DOM Element Button of click
onClickParentDomButton(){
const iframe: any = document.querySelector("#IframeId");
console.log('iframe.contentDocument**', iframe.contentDocument); // here is null
const btn = iframe.contentDocument.body.querySelector("#inSideIframeBtn");
}
If the button <button #submitBtn> you are trying to reference is inside a iframe then you cannot reference it in the parent application using angular view child.
It seems the iframe page is also managed by you and is of same origin as the parent application. If so you can
const iframe = document.querySelector('#myIframe');
const btn = iframe.contentDocument.body.querySelector('#submitBtn');
/// use the btn