lbertenasco / ap-ng2-fullcalendar

Angular2 fullcalendar component
MIT License
35 stars 18 forks source link

How to refresh the calendar #25

Closed gakshat14 closed 7 years ago

gakshat14 commented 7 years ago

Thank you for the library.

I have been using it and I want to refresh the calendar after adding an event please help me on this front. How can I do this??

lbertenasco commented 7 years ago

Hi @gakshat14 , thanks!

How are you adding an event to the calendar? Can you share a snippet of the code and how you are using it?

alan345 commented 7 years ago

Thanks for your work!

Please find a snippet example. It is working for me

import {CalendarComponent} from 'ap-angular2-fullcalendar';

export class ExpenseComponent implements OnInit {
   @ViewChild(CalendarComponent) myCalendar: CalendarComponent;
   events = [] // no event when init
   calendarOptions:Object = {
      events: this.events,
      (...)
   }

   // call this function to update your calendar
   updateCalendar() {
     this.events = [
        {
          title: 'All Day Event',
          start: '2016-09-01'
        },
        {
          title: 'Long Event',
          start: '2016-09-07',
          end: '2016-09-10'
        }]

      let dataSource = {
        id:1,
        events: this.events
      }

      this.myCalendar.fullCalendar('removeEventSources'); // remove all data in your calendar
      this.myCalendar.fullCalendar('addEventSource', dataSource); //add your data updated

    }

}

@lbertenasco is it the correct way to do that?

lbertenasco commented 7 years ago

Hi @alan345 Thanks!

Yes, that is one way to refresh the event sources.

I'm closing the issue since this is a question for StackOverflow/Google and not an issue on the package.