src/app/modules/questionnaire/guard/can-deactivate.guard.ts
Methods |
|
HostListeners |
window:beforeunload |
Arguments : '$event'
|
Abstract canDeactivate |
canDeactivate()
|
Returns :
boolean
|
unloadNotification | ||||||
unloadNotification($event: any)
|
||||||
Decorators :
@HostListener('window:beforeunload', ['$event'])
|
||||||
Parameters :
Returns :
void
|
import { HostListener, Injectable, Directive } from '@angular/core';
import { CanDeactivate } from '@angular/router';
import { ResourceService } from '@sunbird/shared';
@Injectable()
export class CanDeactivateGuard
implements CanDeactivate<ComponentDeactivate> {
constructor(public resourceService: ResourceService) {}
canDeactivate(component: ComponentDeactivate): boolean {
if (!component.canDeactivate()) {
if (
confirm(this.resourceService.frmelmnts.lbl.confirmBackClick)
) {
return true;
} else {
return false;
}
}
return true;
}
}
@Directive()
export abstract class ComponentDeactivate {
abstract canDeactivate(): boolean;
@HostListener('window:beforeunload', ['$event'])
unloadNotification($event: any) {
if (!this.canDeactivate()) {
$event.returnValue = true;
}
}
}