twinssbc / Ionic-Calendar

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

Error While changing the mode to week view #102

Closed ykarthikreddy18 closed 7 years ago

ykarthikreddy18 commented 7 years ago

TypeError: Cannot read property 'NaN' of undefined at Object.ctrl._onDataLoaded (http://localhost:8100/lib/ionic-calendar/dist/js/calendar-tpls.min.js:1:20755) at Object.self.rangeChanged (http://localhost:8100/lib/ionic-calendar/dist/js/calendar-tpls.min.js:1:6683) at Object.self.refreshView (http://localhost:8100/lib/ionic-calendar/dist/js/calendar-tpls.min.js:1:5891) at link (http://localhost:8100/lib/ionic-calendar/dist/js/calendar-tpls.min.js:1:21922) at invokeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:22993:9) at nodeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:22392:11) at delayedNodeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:22750:11) at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21703:13) at publicLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21583:30) at boundTranscludeFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21720:16)

my change mode function is

 $scope.changeMode = function (mode) {
    $scope.calendar.mode = mode;
    };

Html code:

twinssbc commented 7 years ago

Could you debug to see which exact line in _onDataLoaded method throws this error? It seems the error is because trying to access an undefined variable.

ykarthikreddy18 commented 7 years ago

eventSet=rows[startRowIndex][dayIndex].events

At dayIndex it is showing error.. Below is the html I'm using for viewing caledar

<calendar ng-model="calendar.currentDate" calendar-mode="calendar.mode" event-source="calendar.eventSource" range-changed="reloadSource(startTime, endTime)" event-selected="onEventSelected(event)" title-changed="onViewTitleChanged(title)" time-selected="onTimeSelected(selectedTime, events)" monthview-event-detail-template-url="monthviewEventDetailTemplateUrl" step="30" ></calendar>

twinssbc commented 7 years ago

Could you check whats the value in startRowIndex and dayIndex?also in which week you get this error? If you dont pass any events, will this error happen?

ykarthikreddy18 commented 7 years ago

Both startRowIndex and dayIndex are coming as NaN.. and the error is not happening if i'm not passing any event.

Below code is my event generation code..

function createRandomEvents(data) {
            var events = [];
             var startDay = Math.floor(Math.random() * 90) - 45;
                var endDay = Math.floor(Math.random() * 2) + startDay;
            var startMinute = Math.floor(Math.random() * 24 * 60);
            var endMinute = Math.floor(Math.random() * 180) + startMinute;
           for(key in data){
                var startTime;
                var endTime;
                 var date = new Date(data[key].date);
                  startTime = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, date.getMinutes() );
                  endTime = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, date.getMinutes());

                 events.push({
                    id:key,
                        title: 'Event - ' + key,
                        startTime: startTime,
                        endTime: endTime,
                        allDay: false
                    });
            }
             return events;
        }
twinssbc commented 7 years ago

Could u check if all events you passed in having valid startTime and endTime?

ykarthikreddy18 commented 7 years ago

Thankyou for your time @twinssbc .. It is the start time and end time problem. Thankyou for guiding