I have an array of applications
and I want each application to have a new property called Blobs
. I have to make a new HTTP request to get Blobs for every single application and I use switchMap
for that. However, for some reason, it only emits the last application and not every single one.
(bad explanation I know but you'll get the idea when you read the code)
this.serviceOne.getAllApplications(visitId).pipe(
switchMap((applications) => from(applications)),
switchMap((application) => {
console.log("successfully logs every application in applications array");
return forkJoin([
of(application),
this.blobsService.getBlobBs({
visitId,
applicationId: application.id,
}),
]);
}),
map(([application, blobs]) => {
console.log("only logs on last emitted application");
return { ...application, blobs };
}),
toArray()
)
It returns an array with only the last element in it (blobs property is correctly added in that last object tho.)
Whenever I change forkJoin to this:
return forkJoin([
of(application) ,
of([])
]);
It starts to work as it should.
Get Blobs:
getBlobBs(identifier: IIdentifier): Observable<BlobItem[]> {
return this.http.get<BlobItem[]>(
'service url goes here'
)
}