Angular 6 multiple HTTP request RxJs

E Doe

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

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.

Adrian Brand

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related