Chaining http calls in angular 2 in a for loop
问题 I have some code that looks like //service.ts addProduct(productId) { this.http.post('someUrl', ReqData).map(json).subscribe(doStuff); } //component.ts addAllproducts(productsIds) { productIds.forEach(productId => service.addProduct(productId); } What I want is to be able to wait for each call to finish before calling for the next productId, without using window.setTimeout .. 回答1: First return the observable from your service method: addProduct(productId) { return this.http.post('someUrl',