Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!