This is how I am using fullcalendar in my Angular 8 app:
calendar.component.ts:
export class MyCalendarComponent implements OnInit {
public plantedActivities: PlantedActivityModel[]
public actuatorActivities: ActuatorActivityModel[]
events
options
constructor(
private service: CalendarService,
) {
}
ngOnInit() {
this.events = [];
this.options = {
plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin],
defaultDate: '2020-03-01',
header: {
left: 'prev,next',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
editable: true,
dateClick: (e) => {
console.log(e)
},
eventClick: (e) => {
console.log(e)
}
};
this.service.currentAll.subscribe(res => {
this.plantedActivities = res.plantedActivities
for (let plantActivity of this.plantedActivities) {
this.events = [... this.events,
{
"title": "Planted: " + plantActivity.plant.englishName,
"start": plantActivity.date,
type: 'plant'
}];
}
this.actuatorActivities= res.actuatorActivities
for (let actuatorActivity of this.actuatorActivities) {
this.events = [... this.events,
{
"title": actuatorActivity.actuator.title + ": " + actuatorActivity.action_took,
"start": actuatorActivity.date,
type: 'actuator'
}]
}
}
}
calendar.component.html
<div class="container">
<p-fullCalendar [events]="events" [options]=options></p-fullCalendar>
</div>
I am having a big trouble finding a way to control the styling of different event types.
I have tried using ng-fullcalendar and/or ngx-fullcalendar but I am facing different issues on the calendar ui itself, it wont load as it supposed to so I prefer using primeng fullcalendar as i have managed to face any other issue except the styling of the different type of events (bg color of cell, event color, event bg color...)
I think that i should do something like:
this.options = {
...
eventColor: this.eventColor(),
eventTextColor: "#fff",
};
where this.eventColor() would return the color depending on the type of the event, but I dont know how to pass the event parameter inside the function. Is there any way of doing that?
I think I could also find a solution of this by iterating through the events of the calendar after they have been initialized Is there a way of looping through them?
Also, i don't know hot to change the CELL bg-color of an event in general..