Within my current project, I am utilizing a full calendar that loads events dynamically from a database. However, I encountered an issue when attempting to add events to the calendar. It seems like there might be a synchronization problem with the httpget method that prevented me from resolving the issue.
this.events = [];
this.holidayList = [];
this._holidayService.getHolidayArray().subscribe((result: any[]) => {
for (let i = 0; i < result.length; i++) {
this.events.push({ "title": result[i].title, "start": result[i].start });
}
});
this.options = {
plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin],
selectable: true,
selectMirror: true,
select: function (arg) {
var start = arg.start.toString();
var date = start.slice(8, 10);
var year = start.slice(11, 15);
var month = start.slice(4, 7);
//
if (month === "Jan") month = '01';
...
},
defaultDate: '2019-07-01',
header: {
left: 'prev,next',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: this.events
}
}
getHolidayArray() {
return this.ExecuteGet("api/HolidayCalendar/GetTitles");
}
If I try
this._holidayService.getHolidayArray().then(events => { this.events = events; });
an error "then doesn't exist on type observable"