Javascript 如何在angular2中进行顺序http api调用?
我有多个api调用,其中依赖于另一个调用。如何使用rxjs实现这一点?试试这个Javascript 如何在angular2中进行顺序http api调用?,javascript,angular,typescript,rxjs,Javascript,Angular,Typescript,Rxjs,我有多个api调用,其中依赖于另一个调用。如何使用rxjs实现这一点?试试这个 this.serviceInst.firstAPIMethod() .flatMap(firstMethodResult => this.serviceInst.secondAPIMethod(firstMethodResult)) .flatMap(secondMethodResult => this.serviceInst.thirdAPIMethod(secondMethodResu
this.serviceInst.firstAPIMethod()
.flatMap(firstMethodResult => this.serviceInst.secondAPIMethod(firstMethodResult))
.flatMap(secondMethodResult => this.serviceInst.thirdAPIMethod(secondMethodResult))
.subscribe(thirdMethodResult => {
console.log(thirdMethodResult);
});
let inSequence = (tasks) => { // tasks being an array of functions returning promises
return tasks.reduce((p, task) => p.then(task), Promise.resolve());
}
inSequence(tasks).then(() => {
console.log('all requests done');
});