0

I am working on ui-calendar and i would like to fix events from database date fields..

calendarDemoApp.controller('CalendarCtrl',
function($scope, $compile, $timeout, uiCalendarConfig) {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var year;
var mdate;
var month;


// My Method to get Values from Database, After calling the method when i use alerts in within same code the date is showing correctly
alert(year); alert(month); alert(mdate); ---> these gets the value from database and gives the correct value... 


$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!
};
/* event source that contains custom events on the scope */
$scope.events = [
  {title: 'All Day Event',start: new Date(year, month, mdate)},
  {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/'}
];

After getting the database values from the method and displaying in alert, when i use the values in

This is not working..it shows as undefined..

$scope.events = [{title: 'All Day Event', start: new Date(year, month, mdate)}];

can anyone help me how to bring that var values outside that method and declare it in $scope.events to make this work

JavaLearner1
  • 607
  • 2
  • 8
  • 21
  • Your $scope.events is created BEFORE the database has returned with any data. Make year, month and mdate scope variables as well so Angular knows to look out for any changes to them – garethb Apr 20 '16 at 06:21
  • @garethb i declared year, month and mdate as $scope variables. but it shows still undefined outside the function.... – JavaLearner1 Apr 20 '16 at 06:26
  • Can you post your method for getting the values from the database? – garethb Apr 20 '16 at 06:34

0 Answers0