I am trying to use window.onbeforeunload
in my project but I do not know how to use it.
I have tried in 2 ways:
1st way
<
you have to import @HostListener
and use it like below in your component
import { Component, OnInit, HostListener } from '@angular/core';
export class TestComponent implements OnInit {
@HostListener('window:beforeunload', ['$event']) onBeforeUnload(event) {
// do something here
console.log("method called");
}
}