В canDeactivate guard я подписан на подтверждение обслуживания.Компонент подтверждения имеет 3 кнопки, и при нажатии одной из них он выводит enum.Как проверить значение в подписке для просмотра, сделать что-то и вернуть логическое значение для защиты в зависимости от значения?
CanDeactivateGuard:
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
constructor(private modalDialogService: ModalService) {
}
canDeactivate(component: CanComponentDeactivate,
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | boolean {
if (!component.isUnsavedChanges()) {
return true;
}
this.modalDialogService.showConfirm(ConfirmType.CAN_DEACTIVATE).subscribe(val => {
//here I want to check value, do some functions and return true/false
})
}
}
ConfirmComponent:
export class ConfirmComponent {
subject: Subject<ConfirmAction>;
constructor(public bsModalRef: BsModalRef) {}
action(action: ConfirmAction):void { //here the value of click
this.bsModalRef.hide();
this.subject.next(action);
this.subject.complete();
}
}
export enum ConfirmAction {
SAVE,
REVERT,
CANCEl,
}
МодалСервис:
export class ModalService {
constructor(private bsModalService: BsModalService,
private ts: TranslatorService) {}
public showConfirm(modalDialogType: ConfirmType, extraInfo?: string): Observable<ConfirmAction> {
let modal;
switch (modalDialogType) {
case ConfirmType.CAN_DEACTIVATE: {
modal = this.bsModalService.show(ConfirmComponent, config);
break;
}
/*
other cases
*/
return modal.content.subject.asObservable();
}