I would like to call a function when user closes the tab. I have used hostlistener to fire a event when user closes the tab and a popup appears with cancel and leave button. I need to call a function when user clicks the leave button. Below is the code I have written and I need to call myFunction() when user clicks on leave button.
@HostListener('window:beforeunload', ['$event'])
beforeunloadHandler(event) {
event.preventDefault();
return false;
}
myFunction(){
//code
}