16 lines
504 B
TypeScript
16 lines
504 B
TypeScript
// #docregion
|
|
import { Injectable } from '@angular/core';
|
|
import { CanDeactivate } from '@angular/router';
|
|
import { Observable } from 'rxjs/Observable';
|
|
|
|
export interface CanComponentDeactivate {
|
|
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
|
|
}
|
|
|
|
@Injectable()
|
|
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
|
|
canDeactivate(component: CanComponentDeactivate) {
|
|
return component.canDeactivate ? component.canDeactivate() : true;
|
|
}
|
|
}
|