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

177
Views
How to replace setTimeout() in Angular Material Autocomplete

I am trying to use scroll after opening Material Autocomplete to scroll to a specific option using _setScrollTop. It is working fine when I use setTimeout but without it nothing is happening. Is there a way to avoid using timeout?

Here is a live example.

I am using @ViewChild to get autocomplete:

@ViewChild('auto') testAuto: MatAutocomplete;

And then calling autoOpened() function on Autocomplete (opened)

<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete" (opened)="autoOpened()">

autoOpened() {

  // Not working
  this.testAuto._setScrollTop(30);

  // Working
  // setTimeout(() => {
  //   this.testAuto._setScrollTop(30);
  // })
  
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I don't think there is a way to avoid setTimeout in this case. Because autocomplete panel doesn't exist at that moment yet. See Angular Autocomplete sources:

  _setScrollTop(scrollTop: number): void {
    if (this.panel) {
      this.panel.nativeElement.scrollTop = scrollTop;
    }
  }
about 4 years ago · Juan Pablo Isaza Report
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!