1

An angular 4 app. If I close the browser window, will that call the on destory lifecycle hook? Is there a way to act on the browser close action if not?

Why?

disconnection of web sockets

  • got it: https://stackoverflow.com/questions/38999842/angular-2-execute-code-when-closing-window –  Nov 16 '17 at 02:16

1 Answers1

1

OnDestroy does NOT react when you close the window. Although you can hook to the browser window event

@HostListener('window:beforeunload', ['$event'])
handleBeforeUnload(event) {
    this.unsubscribeFromWhatever();
}

This way you can collect garbage from you app

Lasto
  • 107
  • 8