I am struggling to create a dynamic object that I need to frame and then pass to the FullCalendar event input. Here is my initial object:
import { EventInput } from '@fullcalendar/core';
...
events: EventInput[];
this.events = [ { title: '', allDay: false, start: choosenStartDate, end :choosenEndDate, backgroundColor: RateColor.SpecialRate, borderColor: RateColor.SpecialRate },];
If I have multiple objects, I want to push them into an array, but I'm encountering issues.
let obj1:EventInput = { title: '', allDay: false, start: specialRateStartDate, end :specialRateEndDate, backgroundColor: RateColor.SpecialRate, borderColor: RateColor.SpecialRate };
let obj2 :EventInput= { title: '', allDay: false, start: normalRateFirstStartDate, end :normalRateFirstEndDate, backgroundColor: RateColor.NormalRate, borderColor: RateColor.NormalRate };
let obj3:EventInput = { title: '', allDay: false, start: normalRateSecondStartDate, end :normalRateSecondEndDate, backgroundColor: RateColor.NormalRate, borderColor: RateColor.NormalRate }
When I try this.events.push(obj1);
, I get the error
ERROR TypeError: Cannot read property 'push' of undefined
.
One solution that works is setting
this.events=[obj1,obj2,obj3,obj4,obj5...];
, however, I prefer inserting them through a loop.