I need to get the list of dates from the server by using an API HTTP call. After that, I need to display the background color for that date in a calendar.
Here I'm getting data from HTTP call nicely. That data is assigning to one global variable. That global variable is getting "undefined" after assigning data(Which is getting from server).
Global variable Declaration:
unAvailableDays:any=[];
HTTP call:
beforeMonthViewRender(renderEvent: CalendarMonthViewBeforeRenderEvent): void {
let startday =this.datepipe.transform(this.startDate,'MM-dd-yyyy');
let endday = this.datepipe.transform(this.endDate,'MM-dd-yyyy');
this.sharedService.GetUnAvailableTimeSlotsDatesBetweenTwoDatesByMemberID(this.sharedService.MemberID,startday,endday)
.subscribe((data:any) => {
this.unAvailableDays=data,
console.log( this.unAvailableDays)
});
renderEvent.body.forEach(day => {
const dayOfMonth = day.date.getDate();
for(var i =0;i<this.unAvailableDays.length;i++) {
console.log(dayOfMonth);
if(new Date(this.unAvailableDays[i].date).getDate()==dayOfMonth) {
day.cssClass = 'bg-pink';
break;
}
}
});
renderEvent
is calling before data assigning to this.unAvailableDays
which is mentioned inside of HTTP call.
Please Help me.