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

102
Views
Listen when a Dom element appears in Angular

I have a search bar icon 🔍 when you click it the search bar appears ▭

The code responsable for showning the search bar ▭ :

<ion-icon (click)="toggleSearchBar()" name="search"></ion-icon>

The Function:

toggleSearchBar() {
    this.shouldShowSearchBar = !this.shouldShowSearchBar;
    this.searchBarEl.setFocus();
}

But I have this problem:

1- I need to wrap this.searchBarEl.setFocus(); inside setTimeout because the search bar is wrapped inside *ngIf="shouldShowSearchBar" which is not rendered so fast so if I don't wrap the method inside timeout it won't call because the dom element would have not appeared.

Can I listen when a Dom element appears in Angular?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you change *ngIf="shouldShowSearchBar" to [hidden]="!shouldShowSearchBar" then the DOM will already contain the HTML element and you will not have to add setTimeout to your event handling code toggleSearchBar. You could also use ngClass or ngStyle in the same manner with the css display: none.

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!