Reputation: 81
I'm trying to integrate AngularUI's calendar wrapper into my application, and the calendar initialization works fine. However, I don't see how I can call calendar methods from here. Here's my controller code:
$scope.events = [];
$scope.calendarOptions = {
calendar: {
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultView: 'agendaWeek',
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Event Title:');
if (title) {
$scope.$apply(function(){
$scope.events.push({
title: title,
start: start,
end: end,
allDay: allDay
});
});
}
// should call 'unselect' method here
},
editable: true
}
};
$scope.eventSources = [$scope.events];
How do I call methods from the calendar? It's not in my controller's scope, I've checked everywhere inside the scope object.
I found this inside the uiCalendar directive code:
scope: {ngModel:'=',config:'='},
By my understanding, this means that the calendar is created in an isolated scope. So no methods can be called on the calendar. HOWEVER, in the demo I found this line:
/* Change View */
$scope.changeView = function(view) {
$scope.myCalendar.fullCalendar('changeView',view);
};
So the demo can call methods on the calendar and I can't? I can't replicate this either.
Any help understanding or fixing the issue would be appreciated.
Upvotes: 1
Views: 7768
Reputation: 81
Okay, so it was pretty obvious in the source code, but I didn't understand on first glance. Here's a relevant snippet:
if(attrs.calendar){
scope.calendar = scope.$parent[attrs.calendar] = elm.html('');
}else{
scope.calendar = elm.html('');
}
This binds the calendar to the parent scope under the name that you declare when you write the calendar directive in your HTML. e.g.
<div ui-calendar="options" calendar="my-calendar-name" ng-model="events"></div>
This means I can call on the calendar's methods in my controller's scope. It was a feature implementation that I hadn't even considered yet! We need some docs for this script.
Upvotes: 1