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

103
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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