I am using FullCalendar in Angular with rrule pluging and repeating events. I want to change the backgroundColor, textColor etc. inside the eventDidMount callback. However, on using setting multiple props inside the eventDidMount hook, only the last one in order works after any navigation button is pressed. On using backend calls for event, it shows same behavior even before pressing the navigation button. Please provide a way to change multiple properties of the repeating event, based on it's start DateTime.
Here is a demo showcasing the problem - https://stackblitz.com/edit/stackblitz-starters-r8rgqd?file=src%2Fcalendar%2Fcalendar.component.ts
Calendar Options And Event Did Mount:
calendarOptions = {
plugins: [timeGridPlugin, rrulePlugin],
initialView: 'timeGridWeek',
eventSources: [
{// any dummy repeating data with rrule
events: (a: any, success: any, c: any) =>
this.initDummyEvents(a, success, c),
},
],
eventDidMount: (mountArg: EventMountArg) => this.onEventMounted(mountArg),
};
constructor() {}
ngOnInit() {}
onEventMounted(mountArg: EventMountArg) {
if (mountArg.event.extendedProps['type'] === 'break_event') {
// ONLY LAST (textColor) WILL WORK IF NAVIGATION BUTTON IS PRESSE
mountArg.event.setProp('backgroundColor', '#FDDD9F');
mountArg.event.setProp('borderColor', '#202020');
mountArg.event.setProp('textColor', '#202020');
}
// I am not using the eventDataTransform callback because I need the calculated start Date of expanded event
}
I found in the official fullcalendar angular documentation, it is mentioned, specifically for angular I think, that:-
So following the first option in the suggestion, I ended up making the following changes:
Working example on stackblitz. Inside the eventDidMount callback, I create another object of type EventInput using the values from the EventImpl object that is supplied in the callback. I remove the supplied event from the calendar and add this event using the calendar object.
To access the calendar object in order to add the event, make following changes:- In your template, use localreference (like #calendar) in the full-calendar element like
and your component.ts, add:-
use the calendar object like this (inside eventDidMount):-
IMPORTANT NOTE 1:-
When providing event source, make sure you give an id to the event source like this:-
and when adding the event in evenDidMount, provide this id in the Calendar::addEvent method:-
It is important, otherwise, the calendar will not refresh this event when the source is refreshed and you will end up getting an extra event, each time the dates are loaded.
IMPORTANT NOTE 2:-
Make sure when you create the new event input, if necessary, provide a flag that can be used to distinguish that this event is already modified. Otherwise whenever we will add this event, eventDidMount will trigger for it, and remove this event and add it again, triggering another eventDidMount, resulting in an infinite loop. So to deal with this, add an extendedProp during modified input event creation:-
use this extendedProp inside eventDidMount to distinguish the modified events and don't perform the removal/addition action for them:-