I am working in an Angular 4 application ,In my application I have 5 components What I am trying to do is ,When the user close the browser window from any one of the five components I need to call the API and say the user is closed the window on this time .
In my case the API is not get called when I closed the application.
app.component.ts
export class AppComponent implements OnInit {
constructor(private CartdataService: CartdataService, private http: HttpClient) { }
ngOnInit() {}
@HostListener('window:beforeunload', ['$event'])
beforeunloadHandler(event) {
this.WindowClosed();
}
WindowClosed() {
this.CartdataService.get_DummyCall().subscribe();
}
}
Here I haven't implemented anything other than the above code . Can anyone tell me Where I did the mistakes.
Reference :