user6781560
user6781560

Reputation:

on destroy called in angular with browser window closes?

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

Upvotes: 1

Views: 2205

Answers (1)

Lasto
Lasto

Reputation: 127

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

Upvotes: 1

Related Questions