I'm doing a resolver before accessing my component, like this :
return this.unitService.getRoomsByUnitId(unitId)
.map(rooms => {
rooms.map((room: Room) => {
room.beds.map(bed => {
bed.events = new Array();
this.patientStayService.getPatientsBedOccupancyForDateRange(unitId, startDate, endDate)
.subscribe(patientStays => {
patientStays.map(patient => {
if (bed.id === patient.bedId) {
let calendarEvent: CalendarEvent = new CalendarEvent();
calendarEvent.patientStay = patient;
calendarEvent.startDate = patient.admissionPlannedDate;
calendarEvent.endDate = patient.earlyDischargeDate;
bed.events.push(calendarEvent);
}
});
});
});
});
return rooms;
});
But in my component when I get the object "rooms", the informations about the bed and calendarEvent are not already set.
If I do
console.log(bed.events.length);
I always get 0, but If i console log my "rooms" object, I actually have events in my bed object. So I guess when I console log my events.length, the code to set events to bed is not over ?