这个
todo
函数本身应该是异步的,因此它应该返回
Observable
:
private todo(foo): Observable<any> {
const observables = [];
for (let i = 0; i < this.originalData.length; i++) {
observables.push( this.dashboardService.getDetails(this.id1[i], this.id2[i])
};
// notice that dataGroup is an array of latest value of all observables
return forkJoin(observables).map((dataGroup: any[]) => {
// do whatever you want to foo before calling the function
// remember you need to also merge if getFoo returns an observable as well
// but I assume it doesn't
return this.dashboardService.getFoo(foo);
});
}