I have a situation in my Angular 11 service where I am using a Ngbmodal component to subscribe when it is closed. Below is the code snippet:
showMessage(messageData: MessageDataDTO): Observable<MessageResult> {
return new Observable((result) => {
const dialogRef = this.dialog.open(
MessageComponent,
this.ngbModalOptions
);
dialogRef.componentInstance.data = messageData;
dialogRef.closed.subscribe((res) => {
result.next(res);
result.complete();
});
});
}
Is there a way to refactor the code so that I can remove
result.next(res); result.complete();
?