Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

254
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda