I use @HostListener('window:beforeunload')
to detect if a user leaves the page. Then a dialog is opened. If she leaves, I want an event to be fired (or a method to be called). If the user does not leave, I don't want this event to be fired.
If I do:
@HostListener('window:beforeunload')
private someFunction() {
WHATEVER
}
someFunction
is ALWAYS called. I want to know the user's answer before calling this function.
If I read this or this it seems these solutions should work also for my case, but I don't see how they handle the user's choice (whether leave or stay) to know if the function has to be called or not.
Could it be it's related with the $event
I'm not using in @HostListener('window:beforeunload', ['$event'])
?