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

149
Visualizações
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 à 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