angular-ui / ui-calendar

A complete AngularJS directive for the Arshaw FullCalendar.
http://angular-ui.github.io/ui-calendar/
MIT License
1.49k stars 728 forks source link

eventClick not firing #370

Closed GrimGX closed 8 years ago

GrimGX commented 8 years ago

I have added an eventClick to my uiConfig but it will not fire.

Code:

$scope.uiConfig = { calendar: { height: $scope.calendarHeight, editable: false, header: false, eventClick: $scope.eventClick, defaultView: 'agendaDay', selectable: true, select: function (start, end, allDay, jsEvent, view) { alert(start); }, allDaySlot: false, buttonText: { today: "Today" }, titleFormat: "D/MMM/YYYY", businessHours: { start: '08:00', end: '18:00',

            dow: [1, 2, 3, 4, 5, 6, 7]
            // days of week. an array of zero-based day of week integers (0=Sunday)
            // (Monday-Thursday in this example)
        },
        //events: $scope.MyDayEvents
    }
};

then later i add the events to the object using uiCalendarConfig: if (uiCalendarConfig.calendars.MyCalendar == 'undefined') { alert("if"); $scope.MyDayEvents[b] = { id: 1, start: (DATE HERE) }; } else { uiCalendarConfig.calendars.MyCalendar.fullCalendar('renderEvent', { id: 1, start: (DATE HERE) }); }

I have no idea why the eventClick is not firing

GrimGX commented 8 years ago

After 5 hours of trying to get this to work the only way that I could was to embed the eventClick as such:

$scope.uiConfig = { calendar: { height: $scope.calendarHeight, editable: false, header: false, eventClick: function (calEvent, jsEvent, view) {

        },
        defaultView: 'agendaDay',
        selectable: true,
        select: function (start, end, allDay, jsEvent, view) {

        },
        allDaySlot: false,
        buttonText: {
            today: "Today"
        },
        titleFormat: "D/MMM/YYYY",
        businessHours: {
            start: '08:00',
            end: '18:00',

            dow: [1, 2, 3, 4, 5, 6, 7]
        },
    }
};

Hope this helps someone else somewhere along the way

krishnavedula commented 7 years ago

I had the same issue. In my case, I had declared the functions after uiConfig declaration and they were not getting fired. Unlike in JS compilation (which is a two sweep process, so variables and functions can be declared where ever), in angular the functions that you use have to be declared before they can be used.

Once I moved the functions to before the uiConfig declaration, things worked just fine