Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
How to add template reference Variable inside iframe of (button) element in angular 10.x

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");      
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

  1. Directly access element with dom query methods.
const iframe = document.querySelector('#myIframe');
const btn = iframe.contentDocument.body.querySelector('#submitBtn');

/// use the btn
  1. (Preferred) Use window messaging. When the btn inside the iframe is clicked let the page emit a event with window messaging. (This would also work if the iframe content is not of same origin).
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!