I have the following piece of code:
var roomStatementToBeCreated = new RoomStatement();
var roomId = this.bookingRequest.roomDetails.allocations[0].roomId;
this.roomService.get(roomId).then((room) => {
roomStatementToBeCreated.buildingId = +room.building.id_original;
roomStatementToBeCreated.roomTypeId = +room.roomType.id_original;
roomStatementToBeCreated.roomNumber = +room.id_original;
});
In the .then() all the variables get their values. However after that it has to get saved in the DB and it is saved with 0 values. And when debugging it says that after leaving the .then() they have undefined values.
I supposed this issue has to do with scope, however I'm not sure how the roomStatementToBeCreated.buildingId and others can save their values outside of the .then().