I have a method which assigns an array returned from from a http request to another array. The issue is that it appears that after the method completes, the array with the new values becomes empty.
Method with http request.
loadBookingFullRowDataRequest(rowId: number) {
this.bookingFullRowData[rowId] = [];
this.bookingService.getAllBookingData().subscribe(res => {
this.bookingFullRowData = <Booking[]>res[rowId];
console.log('all booking data: ', this.bookingFullRowData, 'rowId: ', rowId);
for (const item of this.bookingFullRowData) {
const itemId = `${item['title']}-rowid-${item['rowid']}-proj-${item['proj']}`;
this.bookingsForm.addControl(itemId, new FormControl(
`${item['content']}`
));
}
});
}
Method which attempts to use the data from the updated array.
launchModal(element) {
const elementId = (event.target as Element).id;
const elementIdArray = String(elementId).split('-');
this.currentRow = parseInt(elementIdArray[2], 10);
this.loadBookingFullRowDataRequest(this.currentRow);
console.log('the whole loaded dta:', this.bookingFullRowData, 'row: ', this.currentRow);
this.modalService.createModal('#bookings-form', null, this.dialogOptions);
}
The console.log just outputs an empty array.
