1 2 3 4 5 6 7 8 9 10 11 12 13 14
import {HostListener} from '@angular/core'; export abstract class ComponentCanDeactivate { abstract canDeactivate(): boolean; @HostListener('window:beforeunload', ['$event']) unloadNotification($event: any) { if (this.canDeactivate()) { $event.returnValue = true; } } }