openaire-library/utils/can-exit.guard.ts

22 lines
461 B
TypeScript
Raw Normal View History

import {Observable} from 'rxjs';
import {Injectable} from '@angular/core';
2023-08-01 13:29:27 +02:00
export interface IDeactivateComponent {
canExit: () => Observable<boolean> | Promise<boolean> | boolean;
}
@Injectable({
providedIn: 'root'
})
2023-08-01 13:29:27 +02:00
export class CanExitGuard {
constructor() {
}
canDeactivate(component: IDeactivateComponent): Observable<boolean> | Promise<boolean> | boolean {
return component.canExit ? component.canExit() : true;
}
}