my effects when erring, calls a method in service to display a dialogue. When dialogue completes, it puts result into an observable.
I have a component that is listening to that observable inside that service. Problem is that the component listens to service the very first time and then it doesn't hear anything.
I'm setting that subject to avoid getting the error message that for first time this.errorService.errorExist$ is not returning anything.
ErrorService
private errorExist = new Subject<boolean>();
errorExist$ = this.errorExist.asObservable();
constructor(public dialog: MatDialog) {
this.errorExist.next(false);
}
handleError() {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: {
title: 'Error Occurred',
btn: 'OKAY'
}
});
dialogRef.afterClosed().pipe(take(1)).subscribe( (result: boolean) => {
console.log('inside the closed and result is: ', result);
if (result) {
this.errorExist.next(true);
}
});
}
Component
constructor(errorService: ErrorService) { }
private subscribeToError() {
this.errorService.errorExist$.pipe(takeUntil(this.destroyed$)).subscribe((x: boolean) => {
console.log('this does not print');
if (x) {
}
}
}