nekken / ng2-fullcalendar

95 stars 47 forks source link

How can I use methods of a component inside EventClick method? #37

Open Tecaa opened 7 years ago

Tecaa commented 7 years ago

I set my calendar options as following in the component ScheduleComponent.ts:

calendarOptions:Object = {
        fixedWeekCount : false,
        editable: true,
        eventLimit: true,
        defaultView: "agendaWeek",
        locale: "es",
        eventClick: this.eventClick,
  };

My event click is inside a component ("ScheduleComponent.ts"), it is:

private eventClick(calEvent, jsEvent, view)
  {
    this.otherFunction("example");
  };

But otherFunction doesn't exist in the callendar scope, it exist in the ScheduleComponent.ts scope, how can I figure it out this problem?

Tecaa commented 7 years ago

I figure it out that using "bind()" function:

calendarOptions:Object = { fixedWeekCount : false, editable: true, eventLimit: true, defaultView: "agendaWeek", locale: "es", eventClick: this.eventClick.bind(this), //bind do the magic };

edwin1028 commented 6 years ago

not working for me

SimonBrazell commented 6 years ago

Thanks @Tecaa, solution works well for this and other callbacks (dayClick, etc.).