I'm trying to make a series of XHR GETs based on results of an initial request. I have an array of observables of the secondary requests I want to make, and I can use Array.map to iterate over them and subscribe in sequence to log all of their returned values, but I cannot understand how to format them into a flattened observable that I can print to the screen using the async pipe's single subscription:
ngOnInit() {
// initial request - returns data on a planet
this.planet$ = this.starWarsService.getEntityById("planets", "1");
this.residentData$ = this.planet$.pipe(
map(planets =>
planets.residents.map(planet =>
// get character data for each resident, `split` just grabs the index to construct the URL
this.starWarsService.getEntityById("people", planet.split("/")[5])
)
),
tap(results => {
results.map(result => {
result.subscribe(data => {
// this prints resident/character data correctly
console.log("data", data);
});
});
})
);
}