Can anybody help me to resolve following error -
source is undefined
and $scope.event is undefined
, here are my codes -
$scope.eventList = function(callback) {
service.event_list($scope, function (response) {
var events = [];
angular.forEach(response,function(event,key){
$scope.events.push({
id: event.id,
title: event.name,
start: event.start_date_time
});
});
callback(events);
console.log($scope.events);
});
}
$scope.eventSources = [$scope.events, $scope.eventList];
I am calling eventList
function from my calendar view like this -
<div ng-controller="eventController" data-ng-init="eventList()" class="main-container">
Updated
app.controller('eventController', function($scope,$http, factoryInfo, service, $routeParams, Lightbox, $route, Upload, $compile) {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$scope.changeTo = 'Hungarian';
/* event source that pulls from google.com */
$scope.eventSource = {
url: "http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic",
className: 'gcal-event', // an option!
currentTimezone: 'America/Chicago' // an option!
};
$scope.events = [];
$scope.eventList = function(callback) {
service.event_list($scope, function (response) {
var events = [];
angular.forEach(response,function(event,key){
console.log(event.name);
$scope.events.push({
id: event.id,
title: event.name,
start: event.start_date_time
});
});
callback(events);
});
}
$scope.eventSources = [$scope.events, $scope.eventList];
/* $scope.events = [
{title: 'All Day Event',start: new Date(y, m, 1)},
{title: 'Long Event',start: new Date(y, m, d - 5),end: new Date(y, m, d - 2)},
{id: 999,title: 'Repeating Event',start: new Date(y, m, d - 3, 16, 0),allDay: false},
{id: 999,title: 'Repeating Event',start: new Date(y, m, d + 4, 16, 0),allDay: false},
{title: 'Birthday Party',start: new Date(y, m, d + 1, 19, 0),end: new Date(y, m, d + 1, 22, 30),allDay: false},
{title: 'Click for Google',start: new Date(y, m, 28),end: new Date(y, m, 29),url: 'http://google.com/'}
];*/
/* event source that calls a function on every view switch */
$scope.eventsF = function (start, end, timezone, callback) {
var s = new Date(start).getTime() / 1000;
var e = new Date(end).getTime() / 1000;
var m = new Date(start).getMonth();
var events = [{
title: 'Feed Me ' + m,
start: s + (50000),
end: s + (100000),
allDay: false,
className: ['customFeed']
}];
callback(events);
};
$scope.calEventsExt = {
color: '#f00',
textColor: 'yellow',
events: [
{
type: 'party',
title: 'Lunch',
start: new Date(y, m, d, 12, 0),
end: new Date(y, m, d, 14, 0),
allDay: false
},
{
type: 'party',
title: 'Lunch 2',
start: new Date(y, m, d, 12, 0),
end: new Date(y, m, d, 14, 0),
allDay: false
},
{
type: 'party',
title: 'Click for Google',
start: new Date(y, m, 28),
end: new Date(y, m, 29),
url: 'http://google.com/'
}
]
};
/* alert on eventClick */
$scope.alertOnEventClick = function (date, jsEvent, view) {
$scope.alertMessage = (date.title + ' was clicked ');
};
/* Render Tooltip */
$scope.eventRender = function (event, element, view) {
element.attr({
'tooltip': event.title,
'tooltip-append-to-body': true
});
$compile(element)($scope);
};
$scope.changeLang = function () {
if ($scope.changeTo === 'Hungarian') {
$scope.uiConfig.calendar.dayNames = ["Vasárnap", "Hétfő", "Kedd", "Szerda", "Csütörtök", "Péntek", "Szombat"];
$scope.uiConfig.calendar.dayNamesShort = ["Vas", "Hét", "Kedd", "Sze", "Csüt", "Pén", "Szo"];
$scope.changeTo = 'English';
} else {
$scope.uiConfig.calendar.dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
$scope.uiConfig.calendar.dayNamesShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
$scope.changeTo = 'Hungarian';
}
};
/* event sources array*/
$scope.eventSources = [$scope.events, $scope.eventSource, $scope.eventsF];
$scope.eventSources2 = [$scope.calEventsExt, $scope.eventsF, $scope.events];
//clear search field value
$scope.clearstudentList = function () {
$scope.searchValue = '';
}
$scope.page = 1;
$scope.type = ($routeParams.type) ? ($routeParams.type) : '';
$scope.event_id = ($routeParams.activity_id) ? ($routeParams.event_id) : '';
$scope.service = ($routeParams.service) ? ($routeParams.service) : '';
$scope.serverPath = factoryInfo.serverPath;
});
When you want to add your events as functions then make sure, start,timezone and callback parameters are given. You used $scope.eventList = function(callback) {}
But it should be like this function( start, end, timezone, callback ) { }
for more see http://fullcalendar.io/docs/event_data/events_function/
I am adding my whole code here. My Controller
$scope.events = [];
$scope.calendarConfig = {
calendar: {
allDaySlot: false,
timezone: 'local',
editable: true,
lang: 'de',
header: {
left: 'title',
center: 'Custom text',
right: 'today prev,next'
},
eventClick: $scope.eventClick,
eventResizeStop: $scope.alertResize,
eventDragStop: $scope.alertDrag,
eventRender: $scope.eventRender,
dayClick: $scope.dayClick
}
};
$scope.myevents = function(start, end, timezone, callback) {
eventsModel.get($scope.calendar_id,$scope.calendar_keyword) // eventsModel called to get events from Google calendar
.success(function(data) {
// $rootScope.myobject = data;
var events = [];
angular.forEach(data,function(event,key){
$scope.events.push({
id: event.id,
title: event.time,
start: event.start
});
});
callback(events);
});
}
$scope.eventSources = [$scope.events,$scope.myevents];
and my html
<div id="my_calendar" class="calendar" ng-model="eventSources" calendar="my_calendar" ui-calendar="calendarConfig.calendar"></div>