I am working on angular 6 project. I am using canDeactivate for my routeGuards and a popup to show route leave message. But the issue is coming at my price-list-guard-service on hover .flatMap(isAllow)=> {
Error: Argument of type '(isAllow: boolean) => boolean' is not assignable to parameter of type '(value: boolean, index: number) => ObservableInput<{}>'..
I wanted to do something like this in price-list-guard.service.ts:
price-list-guard.service.ts
@Injectable()
export class PriceListFormGuard implements CanDeactivate<PriceListFormComponent> {
constructor(private promptService: PromptService) { }
canDeactivate(component: PriceListFormComponent):boolean {
if (component.isDirty) {
this.promptService.showPrompt('Warning', 'Unsaved changes detectect on the current page);
this.promptService.callback.flatMap((isAllow) => {
if (isAllow) {
return true;
} else {
return false;
}
});
}
}
}
prompt-service.ts
@Injectable()
export class PromptService {
title: string;
message: string;
display = 'none';
callback: Subject<boolean>;
constructor() {
this.callback = new Subject<boolean>();
}
showPrompt(title: string, message: string): void {
this.title = title;
this.message = message;
this.display = 'block';
}
close(confirm?: boolean): void {
this.title = null;
this.message = null;
this.display = 'none';
if (confirm != null) {
this.callback.next(confirm);
}
}