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

236
Vistas
How to access a child element that is located inside ng-template by its id in a parent component?

this is pretty straightforward and I could not find any solution that works for me, including reading the Angular documentation.

So, I want to access a child component from its parent by the child's id because I want to use it in Jasmine unit test for the parent component.

The problem is that the child component is inside ng-template.

And I don't have a reference to it. I tried different solutions, none of them work.

This is an example code:
This ng-template is located in the parent component:

<ng-template #templateName>
   <child-component id="child-component"></child-component>
</ng-template>

And in the parent component:

@ViewChild('templateName') template;

How to access the <child-component> </child-component> by its id by the parent?

Any help would bre greatly appreciated!
Thank you!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use something like:

fixture.debugElement.query(By.css('#yourId').nativeElement;

Or you have as well:

fixture.debugElement.query(By.directive(YourComponent)).nativeElement;
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