Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

287
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda