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

257
Visualizações
Calling Async Function in Angular with HTML

In angular, a common way to call a function when a button is clicked is to write:

<button (click)="clickFn()">Click Me!</button>

Then in another file, you'd have your clickFn() function.

My question is: if clickFn() is an asynchronous function, does it need to be called differently in order for the browser to interpret it as an asynchronous function, or is it automatically called as an async function?

I've looked around in the angular docs and on stack overflow, but couldn't find anything on this question.

Edit:

Sure @mikeone, there are many example calls you might want to run for a button. In my project, one feature we have is allowing the user to edit their username. This needs to be asynchronous because we are sending a POST request to a database with the user's updated name and then making sure it has been received and updated before continuing. We may use a promise for this like so:

(In component.ts)

async changeUsername(updatedName: string){
    await new Promise((res,rej)=>{
        // * make call to database and then resolve with code 200
        ...
        res(200)
    })
}
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