Reputation: 15
I am new to Angular 6 and having hard time grasping MergeMap and ConcatMap. What i'm trying to achieve is making an API call that returns following example:
JSON object
I need to take all the inputDatasets.datasetName comma separated to a string and make another api call with that api call will return inputDatasets.version array to update the first API call. I see so many different uses of map and pipe and mergeMap concatMap and little overwhelmed as to which to use and how to implement.
Upvotes: 0
Views: 292
Reputation: 21628
I would use switchMap
service.getSpreadSheetdata().pipe(
map(spreadSheetdata => transformSpreadSheetdata(spreadSheetdata)),
switchMap(transformedSpreadSheetdata => service.apiCall(transformedSpreadSheetdata))
).subscribe(apiData => doStuffWithApiData(apiData));
Call the method to get the spread sheet data, then map it to the shape you need for the api call and then switch map the transformed data to pass it down to the api call.
Upvotes: 1