ui - calendar,$ scope value undefined outside method

时间:2016-04-20 06:07:55

标签: javascript angularjs angularjs-scope fullcalendar ui-calendar

我正在使用ui-calendar,我想修复数据库日期字段中的事件..

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/'}
];

从方法中获取数据库值并在alert中显示后,当我使用

中的值时

这不起作用..显示为未定义..

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

任何人都可以帮助我如何将var值置于该方法之外并在$scope.events中声明它以使其工作

0 个答案:

没有答案