I am trying to get all the data from a chain of observables in a resolver. I first need to make a http call to get all the types and with an array returned, I need to loop through the array of types and get all the data for each type. At the end, I want to return an array or all of the data for each type at once (before navigating to the route).
getAllTypesDataResolverFunction() {
this.getAllTypes()
.flatMap(data => {
let allTypesData = [];
data.forEach(i => {
if(i.type === 4) {
allTypesData.push({'typeObj': i});
return Observable.forkJoin([this.getDataForType(), this.getMoreDataForType()])
.subscribe(data => {
let arrayLength = allTypesData.length-1;
allTypesData[arrayLength].typeObjData = data;
})
}
})
return allTypesData;
}).subscribe(data => {
return data;
})
}
With the code I have right now, the resolver seems to not be complete (or at least not complete the nested observables and thus, the data returned for that observable is undefined in the component. Can anyone suggest a way to resolve this issue? Thanks!