How do I stop for loop if response comes false from the api?. I have below code for api integration. Now currently api is calling as per loop at one time. I want to do call the same api if response from the api is true. Below is my code
for (let i = 0; i < this.fooditemselecteddetails.length; i++) {
this.spinnerService.hide();
//console.log(this.fooditemselecteddetails);
this.common.createAPIService('api/booking/AddConcessions?CinemaId=' + this.cinemaid + '&TransactionId=' + this.temptransaction.TransactionId + '&ItemId=' + this.fooditemselecteddetails[i].id + '&Quantity=' + this.fooditemselecteddetails[i].quantity + "&BookingId=" + this.transactionAPIRequest.ORDER_ID, '').subscribe((result: any) => {
this.spinnerService.hide();
this.addconcession = result;
console.log(this.addconcession);
if (this.addconcession.IsSuccess == true) {
if (i == this.fooditemselecteddetails.length - 1) {
localStorage.setItem("bookingid", this.transactionAPIRequest.ORDER_ID);
this.common.createAPIService('api/booking/FinalBookingDetails?BookingId=' + this.transactionAPIRequest.ORDER_ID, '').subscribe((result2: any) => {
this.vistavalidation = result2;
if (this.vistavalidation.BookingID > 0) {
this.common.createAPIService('api/booking/ContinueTransaction?CinemaId=' + this.cinemaid + '&TransactionId=' + this.temptransaction.TransactionId, '').subscribe((result3: any) => {
if (result3.IsSuccess) {
this.ContinueTransactionresult = result3;
this.showTabOnClick('tabs-4');
}
else {
this.common.ShowNotification("Food Item", result3.Error, "info");
this.spinnerService.hide();
}
});
}
else {
this.common.ShowNotification("Food Item", 'something went wrong, please try again', "info");
this.spinnerService.hide();
}
});
}
}
else {
this.common.ShowNotification("Food Item", result.Error, "error");
this.spinnerService.hide();
}
});
}
I want to call AddConcessions?
this api again if response from this api is true. If it's returns false then stop loop there only.