Whenever a value is emitted in the subject, I want to call another observable.
The issue I am currently facing is that when the first value is emitted to the subject
, it triggers the switchMap
and calls the confirmCsvUpload(...)
function. However, subsequent values trigger the switchMap
but not the confirmCsvUpload(...)
function.
I am seeking assistance in understanding why the function is not being called.
// Definition of Subject
private _confirmCsvUpload = new Subject<{ account: Account, previewData: PreviewData[], previewId: string }>();
// Subscription to the Subject
this._confirmCsvUpload.pipe(
switchMap(previewData => this._uploadCsvService.confirmCsvUpload(previewData.account, previewData.previewData, previewData.previewId))
).subscribe();
// Function that emits a value to the subject (This is not the function that is called in the switchMap())
confirmCsvUpload(): void {
this._confirmCsvUpload.next({ account: this.account, previewData: this._previewData, previewId: this.getPreviewIdFromRoute() });
}