twinssbc / Ionic-Calendar

A calendar directive for Ionic framework
http://twinssbc.github.io/Ionic-Calendar/demo
MIT License
159 stars 73 forks source link

Refresh events on calander #177

Open Raagu1993 opened 5 years ago

Raagu1993 commented 5 years ago

When I redirect to a calendar page I am not seeing any events on week view from the back end. when I click on month view and come back to week view events are loading. Could you please suggest me how to get events in the initial view.

I am new for this technology. so, please suggest me with clear explanation.

twinssbc commented 5 years ago

@Raagu1993 Could you provide your code to demonstrate how do you load the events? The calendar watches the eventSource variable, once you fetch the events, you assign them to the eventSource in your callback method. The calendar should be able to display them.

Raagu1993 commented 5 years ago

I am geting events by calling getEvents function and pushing to "$scope.calendar.eventSource". Kindly find the below code for your reference.

//Get All events Start $scope.getEvents = function(){ miappServices.getEvents($scope.accountId).then(function(response) { $scope.response = response; for(var i=0; i<=$scope.response.length; i++){ $scope.response[i].startTime = new Date(response[i].startTime); $scope.response[i].endTime = new Date(response[i].endTime) $scope.calendar.eventSource.push(response[i]); } }, function(err) { // $scope.calendar.mode = err.details; }) } $scope.getEvents();

//Get All events End

$scope.calendar = { currentDate: new Date(), mode: 'week', eventSource: [ { host : "Raghavendra", subject : "Project Discussion", title: 'Event 1', startTime: new Date(Date.UTC(2018, 11, 7, 5, 00, 00)), endTime: new Date(Date.UTC(2018, 11, 7, 7, 00, 00)), allDay: false } ] };

twinssbc commented 5 years ago

@Raagu1993 Directly pushing element to eventSource doesn't take effect. I explained in the README.

Note In the current version, the calendar controller only watches for the eventSource reference as it's the least expensive. That means only you manually reassign the eventSource value, the controller get notified, and this is usually fit to the scenario when the range is changed, you load a new data set from the backend. In case you want to manually insert/remove/update the element in the eventSource array, you can call broadcast the 'eventSourceChanged' event to notify the controller manually.