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

157
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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