Let's say if have an Array inside an Observable, for each value of that array, it want to make an API call (which returns an Observable again). I'll break it down to a simple example. Because I need to iterate over the first observables values, how do I make sure that data contains the actual data, and not another observable?
I tried switchMap, mergeMap, etc..
const observables = Observable.of([{ id: 1 }, { id: 2 }]);
const data = Observable.of('data');
observables.pipe(
// I tried a lot, something like this
map(values => {
if(Array.isArray(values)) {
values.map(value => value.data = data); // data will be an Observable
}
return values;
})
).subscribe(result => {
console.log(result) // I want: [{ id: 1, data: 'data' }, { ... }]
});