When I click submit, I want to make multiple HTTP requests for every date that I've selected. The code below only assigns the last element of selectedDate to booking.bookDate when I clicked submit.
selectedDate: any = [];
booking: SaveBooking = {
id: 0,
roomId: 0,
buildingId: 0,
bookDate: '',
timeSlots: [],
modules: [],
semesterId: 0,
};
submit() {
var result$;
for (let date of this.selectedDate) {
this.booking.bookDate = date;
result$ = this.bookingService.create(this.booking);
}
}
result$.subscribe(() => {
...this.toasty.success()
});
models > booking.ts:
export interface SaveBooking {
id: number;
semesterId: number;
roomId: number;
buildingId: number;
bookDate: string;
timeSlots: number[];
modules: number[];
}
services > booking.service.ts:
create(booking) {
return this.http.post(this.bookingsEndpoint, booking)
.pipe(map(response => response));
}
{ booking, dates: [date1, date2, ...] }