I have a combination of several async request I need to complete together (doing it with forkJoin) - when doing so, I initiate an object:
export class fullData
{
AProp : any;
BProp : any;
CProp : any;
}
const fullDataObservable : fullData = forkJoin(
{
AProp : this.myFirstSrv.getAProp(),
BProp : this.mySecondsSrv.getBProp(),
CProp : this.myThirdSrv.getCProp()
});
return fullDataObservable;
So far - so good. Now - I have 3 new properties in this object:
export class fullData
{
AProp : any;
BProp : any;
CProp : any;
prop1 : any;
prop2 : any;
prop3 : any;
}
the first of then (prop1) depend on the CProp value (or this.myThirdSrv.getCProp()) as a parameter, when doing a get request, the second (prop2) is a simple manipulation of the first one, and the third one (prop3) is also depending on the second as a parameter in a get request. I've tried using a mergeMap, but it didn't work. What am I doing wrong ?:
gatherAllRelevantData() : any
{
//this.myService.getProp1() return observable after get request
this.myService.getProp1().pipe
(
mergeMap((prop1Value : any[]) =>
{
//this.myService.getResultAfterSimpleManipulation return object, not observable
let prop2Values : any[] = this.myService.getResultAfterSimpleManipulation(prop1Value);
//the this.getProp3Value return observable aftet get request
return this.getProp3Value(prop2Value).pipe(
map(prop3Values =>
{
return { prop1 : prop1Value, prop2 : prop2Values, prop3 : prop3Values };
})
)
}
));
}
This should all done in a resolve function and should initiate the fullData object, by getting data from the this.gatherAllRelevantData (not happening) and without unneeded execution of the this.gatherAllRelevantData:
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any>
{
const fullDataObservable = forkJoin(
{
AProp : this.myFirstSrv.getAProp(),
BProp : this.mySecondsSrv.getBProp(),
CProp : this.myThirdSrv.getCProp(),
prop1 : this.gatherAllRelevantData().map(item => items.prop1),
prop1 : this.gatherAllRelevantData().map(item => items.prop1),
prop1 : this.gatherAllRelevantData().map(item => items.prop1)
});
return fullDataObservable;
}