StickNitro / ngx-fullcalendar

An Angular wrapper for the https://fullcalendar.io module
MIT License
11 stars 14 forks source link

Can't add or remove events programmatically on v4 #10

Closed zellb closed 5 years ago

zellb commented 5 years ago

When trying to add new event or remove a current event from calendar using array's push or splice method Im getting the following error:

TypeError: this.calendar.removeEventSources is not a function
    at FullCalendarComponent.push../node_modules/ngx-fullcalendar/fesm5/ngx-fullcalendar.js.FullCalendarComponent.ngDoCheck (ngx-fullcalendar.js:230)
    at checkAndUpdateDirectiveInline (core.js:22004)
    at checkAndUpdateNodeInline (core.js:23265)
    at checkAndUpdateNode (core.js:23227)
    at debugCheckAndUpdateNode (core.js:23861)
    at debugCheckDirectivesFn (core.js:23821)
    at Object.eval [as updateDirectives] (SchedulersComponent.html:2)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:23813)
    at checkAndUpdateView (core.js:23209)
    at callViewAction (core.js:23450)

Steps to reproduce the behavior:

 this.events.push({
                id: 'e',
                title: 'Friends coming round 2',
                start: '2018-07-29T18:00:00',
                end: '2018-07-29T23:00:00'
            }
       );
martinsiden commented 5 years ago

That's because that method has been removed in v4 of Fullcalendar. If you look at this page: https://fullcalendar.io/docs/v4/release-notes it clearly states that:

removeEventSources | Removed. Instead, use multiple EventSource::remove calls. Group together for performance with batchRendering.

So you should fetch all events that the calendar currently has in memory, and then call remove on each of them. Once that's done, you can add new events using the addEvent method on fullcalendar.

martinsiden commented 5 years ago

Try something like this as a work-around until this component deals with this automatically:

@ViewChild('theCalendar') theCalendar: FullCalendarComponent; let allevents = this.theCalendar.calendar.getEvents(); allevents.forEach(el => { el.remove(); }); events.forEach(el => { this.theCalendar.calendar.addEvent(el); });

StickNitro commented 5 years ago

Fixed in v5.0.0-alpha.1

CrackerakiUA commented 5 years ago

@martinsiden please check https://github.com/StickNitro/ngx-fullcalendar/issues/21