Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda