Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

uiCalendarConfig.calendars is undefined #195

Closed
jonaswindey opened this issue Dec 11, 2014 · 27 comments
Closed

uiCalendarConfig.calendars is undefined #195

jonaswindey opened this issue Dec 11, 2014 · 27 comments

Comments

@jonaswindey
Copy link

When trying to run the demo, I get:
undefined is not an object (evaluating 'uiCalendarConfig.calendars[calendar]')

Tried with both fullcalendar 2.1.1 (as in bower's depencency), or the newest (2.2.3)

@jonaswindey
Copy link
Author

(also tried with bower's latest version of ui-calendar (0.8.1) and the latest beta1)

@joshkurz
Copy link
Contributor

are you injecting uiCalendarConfig into your controller's context?

@jonaswindey
Copy link
Author

Yes,

.controller('CalendardemoCtrl', function ($scope,$compile,uiCalendarConfig) { ..

At what moment are the calendar objects from my view injected in this config, on load of the controller or do I need to listen to an ivent?

@joshkurz
Copy link
Contributor

they are created once the calendar library sets them, so initially if you
are trying to access uiCalendarConfig.calendars in controller, it will
fail. Currently we are not emitting any event to notify when a calendar is
set to the uiCalendarConfig. We could, PR maybe?

As a work around, you could do a watch on the length on the calendars array
in your controller to know when it is created. You just need to make sure
you check if uiCalendarConfig.calendar is truthy and then return its length
in the watcher. That should work.

On Thu, Dec 11, 2014 at 10:58 AM, Jonas Windey notifications@github.com
wrote:

Yes,

.controller('CalendardemoCtrl', function
($scope,$compile,uiCalendarConfig) { ..

At what moment are the calendar objects from my view injected in this
config, on load of the controller or do I need to listen to an ivent?


Reply to this email directly or view it on GitHub
#195 (comment)
.

Josh Kurz
www.joshkurz.net

@jonaswindey
Copy link
Author

Even when everything is loaded and I add a button that calls uiCalendarConfig.calendars, it's still undefined.

<div class="calendar" ng-model="eventSources" calendar="myCalendar" ui-calendar="uiConfig.calendar"></div>
<a class="btn" data-ng-click="test()">Test</a>

in controller:


.controller('CalendarCtrl', function ($scope, $http, $modal, growl, uiCalendarConfig) {

$scope.eventSources = [{
      url: "http://localhost:8080/api/calendar/events"
    }];

$scope.test = function() {
      alert(uiCalendarConfig.calendars);
    }

Anything I could be doing wrong?

I've looked to the source of ui-calendar and actually I don't see the exact place where he adds the calendar to the uiCalendarConfig.calendars ?

@jonaswindey
Copy link
Author

I found the issue.

If you install with bower version 0.9.0-beta1 (bower install angular-ui-calendar#0.9.0-beta.1)
The calendar.js is only 274 lines, whereas the latest version is 289 lines.

Could you bump the version of bower?

@jrzeznik
Copy link

Hello,

I have exactly the same issue.
Quick fix is to overwrite the calendar.js with the latest one from the github repository.

But a clean fix would be far better.
I'm attaching the version of bower.

BR,
Julien

/*

  • Angular Calendar Directive that takes in the [eventSources] nested array object as the ng-model and watches it deeply changes.
  •   Can also take in multiple event urls as a source object(s) and feed the events per view.
    
  •   The calendar will watch any eventSource array and update itself when a change is made.
    
    */

angular.module('ui.calendar', [])
.constant('uiCalendarConfig', {})
.controller('uiCalendarCtrl', ['$scope', '$timeout', function($scope, $timeout){

  var sourceSerialId = 1,
      eventSerialId = 1,
      sources = $scope.eventSources,
      extraEventSignature = $scope.calendarWatchEvent ? $scope.calendarWatchEvent : angular.noop,

      wrapFunctionWithScopeApply = function(functionToWrap){
          var wrapper;

          if (functionToWrap){
              wrapper = function(){
                  // This happens outside of angular context so we need to wrap it in a timeout which has an implied apply.
                  // In this way the function will be safely executed on the next digest.

                  var args = arguments;
                  $timeout(function(){
                      functionToWrap.apply(this, args);
                  });
              };
          }

          return wrapper;
      };

  this.eventsFingerprint = function(e) {
    if (!e.__uiCalId) {
      e.__uiCalId = eventSerialId++;
    }
    // This extracts all the information we need from the event. http://jsperf.com/angular-calendar-events-fingerprint/3
    return "" + e.__uiCalId + (e.id || '') + (e.title || '') + (e.url || '') + (+e.start || '') + (+e.end || '') +
      (e.allDay || '') + (e.className || '') + extraEventSignature(e) || '';
  };

  this.sourcesFingerprint = function(source) {
      return source.__id || (source.__id = sourceSerialId++);
  };

  this.allEvents = function() {
    // return sources.flatten(); but we don't have flatten
    var arraySources = [];
    for (var i = 0, srcLen = sources.length; i < srcLen; i++) {
      var source = sources[i];
      if (angular.isArray(source)) {
        // event source as array
        arraySources.push(source);
      } else if(angular.isObject(source) && angular.isArray(source.events)){
        // event source as object, ie extended form
        var extEvent = {};
        for(var key in source){
          if(key !== '_uiCalId' && key !== 'events'){
             extEvent[key] = source[key];
          }
        }
        for(var eI = 0;eI < source.events.length;eI++){
          angular.extend(source.events[eI],extEvent);
        }
        arraySources.push(source.events);
      }
    }

    return Array.prototype.concat.apply([], arraySources);
  };

  // Track changes in array by assigning id tokens to each element and watching the scope for changes in those tokens
  // arguments:
  //  arraySource array of function that returns array of objects to watch
  //  tokenFn function(object) that returns the token for a given object
  this.changeWatcher = function(arraySource, tokenFn) {
    var self;
    var getTokens = function() {
      var array = angular.isFunction(arraySource) ? arraySource() : arraySource;
      var result = [], token, el;
      for (var i = 0, n = array.length; i < n; i++) {
        el = array[i];
        token = tokenFn(el);
        map[token] = el;
        result.push(token);
      }
      return result;
    };
    // returns elements in that are in a but not in b
    // subtractAsSets([4, 5, 6], [4, 5, 7]) => [6]
    var subtractAsSets = function(a, b) {
      var result = [], inB = {}, i, n;
      for (i = 0, n = b.length; i < n; i++) {
        inB[b[i]] = true;
      }
      for (i = 0, n = a.length; i < n; i++) {
        if (!inB[a[i]]) {
          result.push(a[i]);
        }
      }
      return result;
    };

    // Map objects to tokens and vice-versa
    var map = {};

    var applyChanges = function(newTokens, oldTokens) {
      var i, n, el, token;
      var replacedTokens = {};
      var removedTokens = subtractAsSets(oldTokens, newTokens);
      for (i = 0, n = removedTokens.length; i < n; i++) {
        var removedToken = removedTokens[i];
        el = map[removedToken];
        delete map[removedToken];
        var newToken = tokenFn(el);
        // if the element wasn't removed but simply got a new token, its old token will be different from the current one
        if (newToken === removedToken) {
          self.onRemoved(el);
        } else {
          replacedTokens[newToken] = removedToken;
          self.onChanged(el);
        }
      }

      var addedTokens = subtractAsSets(newTokens, oldTokens);
      for (i = 0, n = addedTokens.length; i < n; i++) {
        token = addedTokens[i];
        el = map[token];
        if (!replacedTokens[token]) {
          self.onAdded(el);
        }
      }
    };
    return self = {
      subscribe: function(scope, onChanged) {
        scope.$watch(getTokens, function(newTokens, oldTokens) {
          if (!onChanged || onChanged(newTokens, oldTokens) !== false) {
            applyChanges(newTokens, oldTokens);
          }
        }, true);
      },
      onAdded: angular.noop,
      onChanged: angular.noop,
      onRemoved: angular.noop
    };
  };

  this.getFullCalendarConfig = function(calendarSettings, uiCalendarConfig){
      var config = {};

      angular.extend(config, uiCalendarConfig);
      angular.extend(config, calendarSettings);

      angular.forEach(config, function(value,key){
        if (typeof value === 'function'){
          config[key] = wrapFunctionWithScopeApply(config[key]);
        }
      });

      return config;
  };

}])
.directive('uiCalendar', ['uiCalendarConfig', '$locale', function(uiCalendarConfig, $locale) {
// Configure to use locale names by default
var tValues = function(data) {
// convert {0: "Jan", 1: "Feb", ...} to ["Jan", "Feb", ...]
var r, k;
r = [];
for (k in data) {
r[k] = data[k];
}
return r;
};
var dtf = $locale.DATETIME_FORMATS;
uiCalendarConfig = angular.extend({
monthNames: tValues(dtf.MONTH),
monthNamesShort: tValues(dtf.SHORTMONTH),
dayNames: tValues(dtf.DAY),
dayNamesShort: tValues(dtf.SHORTDAY)
}, uiCalendarConfig || {});

return {
  restrict: 'A',
  scope: {eventSources:'=ngModel',calendarWatchEvent: '&'},
  controller: 'uiCalendarCtrl',
  link: function(scope, elm, attrs, controller) {

    var sources = scope.eventSources,
        sourcesChanged = false,
        eventSourcesWatcher = controller.changeWatcher(sources, controller.sourcesFingerprint),
        eventsWatcher = controller.changeWatcher(controller.allEvents, controller.eventsFingerprint),
        options = null;

    function getOptions(){
      var calendarSettings = attrs.uiCalendar ? scope.$parent.$eval(attrs.uiCalendar) : {},
          fullCalendarConfig;

      fullCalendarConfig = controller.getFullCalendarConfig(calendarSettings, uiCalendarConfig);

      options = { eventSources: sources };
      angular.extend(options, fullCalendarConfig);

      var options2 = {};
      for(var o in options){
        if(o !== 'eventSources'){
          options2[o] = options[o];
        }
      }
      return JSON.stringify(options2);
    }

    scope.destroy = function(){
      if(attrs.calendar) {
        scope.calendar = scope.$parent[attrs.calendar] =  elm.html('');
      } else {
        scope.calendar = elm.html('');
      }
    };

    scope.init = function(){
      scope.calendar.fullCalendar(options);
    };

    eventSourcesWatcher.onAdded = function(source) {
      scope.calendar.fullCalendar('addEventSource', source);
      sourcesChanged = true;
    };

    eventSourcesWatcher.onRemoved = function(source) {
      scope.calendar.fullCalendar('removeEventSource', source);
      sourcesChanged = true;
    };

    eventsWatcher.onAdded = function(event) {
      scope.calendar.fullCalendar('renderEvent', event);
    };

    eventsWatcher.onRemoved = function(event) {
      scope.calendar.fullCalendar('removeEvents', function(e) { return e === event; });
    };

    eventsWatcher.onChanged = function(event) {
      scope.calendar.fullCalendar('updateEvent', event);
    };

    eventSourcesWatcher.subscribe(scope);
    eventsWatcher.subscribe(scope, function(newTokens, oldTokens) {
      if (sourcesChanged === true) {
        sourcesChanged = false;
        // prevent incremental updates in this case
        return false;
      }
    });

    scope.$watch(getOptions, function(newO,oldO){
        scope.destroy();
        scope.init();
    });
  }
};

}]);

@joshkurz
Copy link
Contributor

for sure, will release a new version soonish.

On Fri, Dec 12, 2014 at 6:30 AM, jrzeznik notifications@github.com wrote:

Hello,

I have exactly the same issue.
Quick fix is to overwrite the calendar.js with the latest one from the
github repository.

But a clean fix would be far better.
I'm attaching the version of bower.

BR,
Julien

/*

  • AngularJs Fullcalendar Wrapper for the JQuery FullCalendar
  • API @ http://arshaw.com/fullcalendar/ *
  • Angular Calendar Directive that takes in the [eventSources] nested
    array object as the ng-model and watches it deeply changes.
  • Can also take in multiple event urls as a source object(s) and feed
    the events per view.
  • The calendar will watch any eventSource array and update itself when
    a change is made. * */

angular.module('ui.calendar', [])
.constant('uiCalendarConfig', {})
.controller('uiCalendarCtrl', ['$scope', '$timeout', function($scope,
$timeout){

var sourceSerialId = 1,
eventSerialId = 1,
sources = $scope.eventSources,
extraEventSignature = $scope.calendarWatchEvent ? $scope.calendarWatchEvent : angular.noop,

  wrapFunctionWithScopeApply = function(functionToWrap){
      var wrapper;

      if (functionToWrap){
          wrapper = function(){
              // This happens outside of angular context so we need to wrap it in a timeout which has an implied apply.
              // In this way the function will be safely executed on the next digest.

              var args = arguments;
              $timeout(function(){
                  functionToWrap.apply(this, args);
              });
          };
      }

      return wrapper;
  };

this.eventsFingerprint = function(e) {
if (!e.__uiCalId) {
e.__uiCalId = eventSerialId++;
}
// This extracts all the information we need from the event. http://jsperf.com/angular-calendar-events-fingerprint/3
return "" + e.__uiCalId + (e.id || '') + (e.title || '') + (e.url || '') + (+e.start || '') + (+e.end || '') +
(e.allDay || '') + (e.className || '') + extraEventSignature(e) || '';
};

this.sourcesFingerprint = function(source) {
return source.__id || (source.__id = sourceSerialId++);
};

this.allEvents = function() {
// return sources.flatten(); but we don't have flatten
var arraySources = [];
for (var i = 0, srcLen = sources.length; i < srcLen; i++) {
var source = sources[i];
if (angular.isArray(source)) {
// event source as array
arraySources.push(source);
} else if(angular.isObject(source) && angular.isArray(source.events)){
// event source as object, ie extended form
var extEvent = {};
for(var key in source){
if(key !== '_uiCalId' && key !== 'events'){
extEvent[key] = source[key];
}
}
for(var eI = 0;eI < source.events.length;eI++){
angular.extend(source.events[eI],extEvent);
}
arraySources.push(source.events);
}
}

return Array.prototype.concat.apply([], arraySources);

};

// Track changes in array by assigning id tokens to each element and watching the scope for changes in those tokens
// arguments:
// arraySource array of function that returns array of objects to watch
// tokenFn function(object) that returns the token for a given object
this.changeWatcher = function(arraySource, tokenFn) {
var self;
var getTokens = function() {
var array = angular.isFunction(arraySource) ? arraySource() : arraySource;
var result = [], token, el;
for (var i = 0, n = array.length; i < n; i++) {
el = array[i];
token = tokenFn(el);
map[token] = el;
result.push(token);
}
return result;
};
// returns elements in that are in a but not in b
// subtractAsSets([4, 5, 6], [4, 5, 7]) => [6]
var subtractAsSets = function(a, b) {
var result = [], inB = {}, i, n;
for (i = 0, n = b.length; i < n; i++) {
inB[b[i]] = true;
}
for (i = 0, n = a.length; i < n; i++) {
if (!inB[a[i]]) {
result.push(a[i]);
}
}
return result;
};

// Map objects to tokens and vice-versa
var map = {};

var applyChanges = function(newTokens, oldTokens) {
  var i, n, el, token;
  var replacedTokens = {};
  var removedTokens = subtractAsSets(oldTokens, newTokens);
  for (i = 0, n = removedTokens.length; i < n; i++) {
    var removedToken = removedTokens[i];
    el = map[removedToken];
    delete map[removedToken];
    var newToken = tokenFn(el);
    // if the element wasn't removed but simply got a new token, its old token will be different from the current one
    if (newToken === removedToken) {
      self.onRemoved(el);
    } else {
      replacedTokens[newToken] = removedToken;
      self.onChanged(el);
    }
  }

  var addedTokens = subtractAsSets(newTokens, oldTokens);
  for (i = 0, n = addedTokens.length; i < n; i++) {
    token = addedTokens[i];
    el = map[token];
    if (!replacedTokens[token]) {
      self.onAdded(el);
    }
  }
};
return self = {
  subscribe: function(scope, onChanged) {
    scope.$watch(getTokens, function(newTokens, oldTokens) {
      if (!onChanged || onChanged(newTokens, oldTokens) !== false) {
        applyChanges(newTokens, oldTokens);
      }
    }, true);
  },
  onAdded: angular.noop,
  onChanged: angular.noop,
  onRemoved: angular.noop
};

};

this.getFullCalendarConfig = function(calendarSettings, uiCalendarConfig){
var config = {};

  angular.extend(config, uiCalendarConfig);
  angular.extend(config, calendarSettings);

  angular.forEach(config, function(value,key){
    if (typeof value === 'function'){
      config[key] = wrapFunctionWithScopeApply(config[key]);
    }
  });

  return config;

};

}])
.directive('uiCalendar', ['uiCalendarConfig', '$locale',
function(uiCalendarConfig, $locale) {
// Configure to use locale names by default
var tValues = function(data) {
// convert {0: "Jan", 1: "Feb", ...} to ["Jan", "Feb", ...]
var r, k;
r = [];
for (k in data) {
r[k] = data[k];
}
return r;
};
var dtf = $locale.DATETIME_FORMATS;
uiCalendarConfig = angular.extend({
monthNames: tValues(dtf.MONTH),
monthNamesShort: tValues(dtf.SHORTMONTH),
dayNames: tValues(dtf.DAY),
dayNamesShort: tValues(dtf.SHORTDAY)
}, uiCalendarConfig || {});

return {
restrict: 'A',
scope: {eventSources:'=ngModel',calendarWatchEvent: '&'},
controller: 'uiCalendarCtrl',
link: function(scope, elm, attrs, controller) {

var sources = scope.eventSources,
    sourcesChanged = false,
    eventSourcesWatcher = controller.changeWatcher(sources, controller.sourcesFingerprint),
    eventsWatcher = controller.changeWatcher(controller.allEvents, controller.eventsFingerprint),
    options = null;

function getOptions(){
  var calendarSettings = attrs.uiCalendar ? scope.$parent.$eval(attrs.uiCalendar) : {},
      fullCalendarConfig;

  fullCalendarConfig = controller.getFullCalendarConfig(calendarSettings, uiCalendarConfig);

  options = { eventSources: sources };
  angular.extend(options, fullCalendarConfig);

  var options2 = {};
  for(var o in options){
    if(o !== 'eventSources'){
      options2[o] = options[o];
    }
  }
  return JSON.stringify(options2);
}

scope.destroy = function(){
  if(attrs.calendar) {
    scope.calendar = scope.$parent[attrs.calendar] =  elm.html('');
  } else {
    scope.calendar = elm.html('');
  }
};

scope.init = function(){
  scope.calendar.fullCalendar(options);
};

eventSourcesWatcher.onAdded = function(source) {
  scope.calendar.fullCalendar('addEventSource', source);
  sourcesChanged = true;
};

eventSourcesWatcher.onRemoved = function(source) {
  scope.calendar.fullCalendar('removeEventSource', source);
  sourcesChanged = true;
};

eventsWatcher.onAdded = function(event) {
  scope.calendar.fullCalendar('renderEvent', event);
};

eventsWatcher.onRemoved = function(event) {
  scope.calendar.fullCalendar('removeEvents', function(e) { return e === event; });
};

eventsWatcher.onChanged = function(event) {
  scope.calendar.fullCalendar('updateEvent', event);
};

eventSourcesWatcher.subscribe(scope);
eventsWatcher.subscribe(scope, function(newTokens, oldTokens) {
  if (sourcesChanged === true) {
    sourcesChanged = false;
    // prevent incremental updates in this case
    return false;
  }
});

scope.$watch(getOptions, function(newO,oldO){
    scope.destroy();
    scope.init();
});

}
};

}]);


Reply to this email directly or view it on GitHub
#195 (comment)
.

Josh Kurz
www.joshkurz.net

@pbajsarowicz
Copy link

pbajsarowicz commented Dec 20, 2014

Thanks to @jrzeznik post I can get access to the uiCalendarConfig.calendars list but actually the list is empty...

> uiCalendarConfig.calendars
< Object {}

... when there should be at least one element:

<div ui-calendar="uiConfig.calendar" ng-model="eventSources" calendar="myCalendar">

I've checked all my bower dependencies and they seem to be correct.
This issue happens with:

"angular-ui-calendar": "0.9.0-beta.1",
"fullcalendar": "2.1.1"

Any suggestions/ideas why can't I see the myCalendar in controller?
Thanks in advance.

edit:
Kind of silly but the thing that helped was reinstall angular-ui-calendar and update calendar.js (to current master branch version).

@shenlong
Copy link

shenlong commented Jan 5, 2015

@jonaswindey gives us the fixed. Just go to the github and copy calendar.js and replace it to bower_components\angular-ui-calendar\src

Apparently, bower is not updated with the latest fix.
Cheers.

@jscti
Copy link

jscti commented Jan 23, 2015

+1 for this issue.

Manually patching it isn't a solution for me though. Will wait for a bower update.

@monkeymonk
Copy link

+1

2 similar comments
@elropero
Copy link

+1

@couda
Copy link

couda commented Mar 13, 2015

+1

@monkeymonk
Copy link

As a workaround, I find somewhere (...you know Google) an answer to access the Fullcalendar object, even when working with the controllerAs syntax. The answer: $scope !

Example:

<div ng-controller="ScheduleController as schedule">
    <div ui-calendar="schedule.config.calendar" calendar="calendar" ng-model="schedule.eventSources"></div>
</div>
angular.module('schedule', ['ui.calendar'])
.controller('ScheduleController', ScheduleController);

function ScheduleController($scope, $timeout, uiCalendarConfig) {
    this.config = {...};
    this.eventSources = [{...}];

    // ʕ•ᴥ•ʔ <( ... )

    $timeout(function () {
        // ᕕ( ᐛ )ᕗ <( Yippee! )
        $scope.calendar.fullcalendar('render');
    });
}

Hope that helps!

@Reidsy
Copy link

Reidsy commented Mar 18, 2015

As an alternative workaround, instead of patching calendar.js you can include the git repository and commit id in your bower.json dependencies. Adding the following line in dependencies solved the issue for me:

"angular-ui-calendar": "https://github.com/angular-ui/ui-calendar.git#81069d1945bea8ad1727cf5f44096f58d872a96b"

@jbeynar
Copy link

jbeynar commented Mar 24, 2015

+1

thanks @Reidsy that works with uiCalendarConfig object !

@miljank
Copy link

miljank commented Mar 31, 2015

I'm experiencing somewhat similar problems even with the latest calendar.js.

<div id="calendar" ui-calendar="uiConfig.calendar" ng-model="myEvents" calendar="myCalendar"></div>
console.log(uiCalendarConfig);
console.log(uiCalendarConfig.calendars);

Gives:

Object {calendars: {myCalendar: n.fn.init[1] ...
Object {}

So uiCalendarConfig.calendars.myCalendar is there, but only if I dump uiCalendarConfig content. If I try to access it or uiCalendarConfig.calendars directly it becomes undefined. Any ideas?

@maheshkaranjkar
Copy link

I was experiencing same issue @Reidsy sollution worked for me ...
Thanks

@diosney
Copy link

diosney commented May 8, 2015

Bump.

Almost six months have been passed now and still there is no clean fix to this issue (the bower update way)

:(

@joshkurz
Copy link
Contributor

joshkurz commented May 8, 2015

turn that frown upside down. Should be good now. :)

On Fri, May 8, 2015 at 9:47 AM, Diosney Sarmiento notifications@github.com
wrote:

Bump.

Almost six months have been passed now and still there is no clean fix to
this issue (the bower update way)

:(


Reply to this email directly or view it on GitHub
#195 (comment)
.

Josh Kurz
www.joshkurz.net

@diosney
Copy link

diosney commented May 8, 2015

I tested it and it grabbed the 1.0 version, which is already ok.

Thanks :)

@joshkurz joshkurz closed this as completed May 8, 2015
@dalibenali
Copy link

Hi, i want display in calendar view many json objects from my rest api :
[[{"id":1,"title":"Event 1","start":"2015-09-01","_id":1},{"id":1,"title":"JPO","start":"2015-08-08","_id":2},{"id":2,"title":"Réunion","start":"2015-08-10","_id":3}]]

my broblem : I can display this static json objects fron my controller in the calendar, but when I called my rest api to retrieve the json events they no longer appear in the calendar.

controller:
eventController.controller('EventCtrl', ['$scope', '$compile', 'UserService', 'GetEventsByUserId',
function($scope,$compile,UserService,GetEventsByUserId) {

    $scope.renderCalendar = true;
$scope.eventSources = [];

// static object for test display
$scope.events = [{
    id: 1,
    title: 'Event 1',
    start: "2015-09-01"

}];

//$scope.eventSources = [$scope.events];

$scope.alertEvent = function (event, jsEvent, ui, view) {

    $timeout(function() {
    var sEvent = findCalendarEvent(event);
    sEvent.start = event.start.toDate();
    //sEvent.end = event.end.toDate();
    // by making this dirty we tell uiCalendar to not send updates
    // to fullCalendar.
    //sEvent.isDirty = true;
    });
};


// callback on resize
$scope.alertResize = function(){
    alert('resize !');
};
// callback on drag & drop
$scope.alertDrag = function(){
    alert('Drag !');
};

$scope.calendarConfig = {
    calendar: {
        allDaySlot: false,
        height: 450,
        //defaultView: 'agendaWeek',
        timezone: 'local',
        editable: true,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        eventResizeStop: $scope.alertResize,
        eventDragStop: $scope.alertDrag,
        eventRender: $scope.eventRender
    }
};


var user = UserService.getCurrentUser();
var userId = user.details.id; 
alert(userId);

GetEventsByUserId.query({'id':userId}).$promise.then(function(data) {
    angular.forEach(data,function(event,key){
        $scope.events.push({id: event.id, title: event.name, start:        moment(event.createdAt).format("YYYY-MM-DD")});
    });
    console.log(data);

});
$scope.eventSources = [$scope.events];

}]);
and in my view calendar :

think's ;)

@svashisth07
Copy link

how i can set initial month and year in ui-calander

@olefrank
Copy link

This works for me (ui-calendar v1.0.2):

HTML:

<div ui-calendar="uiConfig.calendar" calendar="myCalendar" data-ng-model="eventSources"></div>

Controller:

uiCalendarConfig.calendars.myCalendar.fullCalendar('rerenderEvents');

@htrampe
Copy link

htrampe commented Jan 14, 2017

For me it does not..any ideas?
Controller:
uiCalendarConfig.calendars.calendar.fullCalendar('rerenderEvents');
HTML:
<div ui-calendar="uiConfig.calendar" calendar="calendar" ng-model="eventSources"></div>

@lubochka
Copy link

When using ui-calendar edited events are not updated.
There is a bug in fullCalendar.js
in function filterLegacyEventInstances
fix from
return legacyEventInstance.id == legacyQuery;

to
return legacyEventInstance._id == legacyQuery;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests