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

155
Views
Call API on close of browser

I am creating project using angular. In my project i need to clear the session when user close the browser. I am doing this with below code

@HostListener('window:beforeunload')
  async ngOnDestroy()
  {
    await  this.someservice.logout.subscribe();
    debugger;
  }

But the problem is this api call never completed and session is not clearing.

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

0

I have something a little different for when user closes the browser in order to clear out the localStorage. I am not using the var event but kept it just so I could see and play around with what does get passed in.

@HostListener('window:beforeunload', ['$event'])
unloadHandler(event: Event)
{
 localStorage.removeItem('storageName');
}

I have not had any issues with the above clearing out values.

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!