nekken / ng2-fullcalendar

95 stars 47 forks source link

Call fullcalendar events like renderEvent #10

Open cmeijerink opened 7 years ago

cmeijerink commented 7 years ago

How can i add an event by calling renderEvent?

stevie1706 commented 7 years ago

You cant do this directly through this directive as the methods would need implemented in the component. I am waiting for the owner to reply but if they have no intention of doing so i will fork and create a typescript interface and the methods for the component.

for now.... import jquery at top of component and then use

$('angular2-fullcalendar').fullCalendar('method', obj);

cmeijerink commented 7 years ago

thnx @stevie1706,

I did get it running that way. For anybody also interested.

When working with dynamic data from a service. Do use zone->run() to force a "scope.apply()".

In my constructor: ''' this.calendarOptions.eventReceive = this.eventReceive; '''

the funcion:

private eventReceive = ( event: any ) => {

        this.zone.run(() => {
             ........
                    this._callendarService.addEvent(result.event).subscribe(
                        result => {
                            this.j_calendar.fullCalendar('refetchEvents');
                        },
                        error => this.errorMessage = <any>error);
                };
.............

In which j_calendar is:

@ViewChild('calendar') calendar: any;

ngAfterViewInit() {

        setTimeout(() => {
            this.j_calendar = <any>$(this.calendar.nativeElement); 
       }
       ........