I mean, I want to track when a user leaves the app, closing browser or tabs.
Components and Directives has a lifecycle hook called ngOnDestroy, which is called when the component is destroyed, but it can't catch when the user leaves the app
import { Component, OnInit } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'app',
templateUrl: 'app.component.html'
})
export class AppComponent implements OnDestroy {
constructor() { }
ngOnDestroy() {
alert(`I'm leaving the app!`);
}
}
If the user closes the browser, the alert is not executed.