for (var i = 0; i < pricingPlans.length; i++) {
productServices.retrivePricingPlan(pricingPlans[i].Id.Value).then(function (objPricingPlan) {
productServices.createPricingPlan(objPricingPlan.data).then(function (objNewPricingPlan) {
var newPlanID = objNewPricingPlan.data.PricingPlan.Id.Value;
console.log("New ID");
console.log(newPlanID);
console.log("Old ID");
console.log(product.PricingPlanAssociations[i].PricingPlanId.value);
// product.PricingPlanAssociations[i].PricingPlanId.value = newPlanID
});
});
}
I am making REST calls inside the for loop, but I want the REST calls to execute in following order:
- Retrieve pricing plan[i]
- Create pricing plan[i]
- Create product[i]
but when I look at the console tab they are executing in a different order
How can I ensure the pricing plans are executed in that particular order inside the for loop?
NOTE: retrivePricingPlan and createPricingPlan return calls to $http.post().
