To demonstrate the problem, I will explain what I am trying to achieve. I create a booking system using the AngularUI calendar, and the problem is that the calendar performance starts to decline very quickly and noticeably when the number of events increases (100+ events, and it takes minutes for the calendar to bind data). Because of this, I am trying to extract data from the back-end when the view changes, sending an AJAX request every time the user changes the view (week, month, day, previous, next ... etc.). This is when I start to have problems.
As suggested on the AngularUI Calendar website, I can use this function: $scope.eventsF = function (start, end, timezone, callback) {...} and add it to $scope.eventSources , and it will be called on each review switch. I added $scope.eventsF to my $scope.eventSources , but it has never been updated.
Here is an example (sampling all the data and their work):
$scope.mainEvents = []; //To initiate the event source Event.getEvents().then(function (events) { // Event is a factory if (events) { //Checking if I have events // If I try: $scope.mainEvents = events; the $scope.eventSources won't update angular.forEach(events, function(value) { this.push(value); }, $scope.mainEvents); } else { // Tell the user no events to render... } }, function (error) { console.log(error); }); $scope.eventSources = [$scope.mainEvents, $scope.draftEvents];
Now I changed Event.getEvents() to take two parameters as the start and end dates of the date, send them to the end and get the data as json again (worked fine, I console this).
Here is the code (I tried two ways): Events is a rendering, but $scope.eventSources not updated in both of them.
At first:
$scope.mainEvents = function (start, end, timezone, callback) { var s = start.format('YYYY-MM-DD'), e = end.format('YYYY-MM-DD'); Event.getEvents(s, e).then(function (events) { $scope.mainEvents = []; //even tried $scope.eventSources.mainEvents if (events) { angular.forEach(events, function (value) { this.push(value); }, $scope.mainEvents); //event tried $scope.eventSources.mainEvents callback($scope.mainEvents); } }, function (error) { console.log(error); }); }; $scope.eventSources = [$scope.mainEvents, $scope.draftEvents];
Second:
$scope.eventsF = function (start, end, timezone, callback) { var s = start.format('YYYY-MM-DD'), e = end.format('YYYY-MM-DD'); Event.getEvents(s, e).then(function (events) { $scope.mainEvents = []; if (events) { angular.forEach(events, function (value) { this.push(value); }, $scope.mainEvents); callback($scope.mainEvents); } }, function (error) { console.log(error); }); }; $scope.eventSources = [$scope.mainEvents, $scope.draftEvents, $scope.eventsF];
Hope this is clear enough.