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

148
Vistas
Element ref not working for the second children component in the parent component

Hello I have a situation where I use same child component twice in parent component. Children component is a dropdown. I use element ref for accessing dropdown from a parent component, but there is a problem that it returns the first element that matches a given component, so it always do things for the first children component and not the second which I use in parent component. My question how to target second child component I use in parent component? I added some pseudo code to better understand my question.

Parent component HTML

<app-dropdown></app-dropdown> <app-dropdown></app-dropdown>

Parent component TS

this.child.dropdownToggleRef.nativeElement.focus();

Children component TS

@ViewChild('dropdownToggleRef') dropdownToggleRef: ElementRef;

Children component HTML

<div
  #dropdownToggleRef
  [class.open]="open"
  [ngClass]="{ 'more mx-right': ellipsisMode }"
  [attr.aria-label]="ariaLabel"
  [attr.aria-haspopup]="true"
  [attr.aria-expanded]="open"
  [tabIndex]="disabled ? -1 : 0"
  [autofocus]="focus"
>
</div>
about 4 years ago · Juan Pablo Isaza
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