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

253
Views
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
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!