Please solve this issue


#1

@ramon @max @perry @siddhartha @mhartington cordova plugin add https://github.com/VitaliiBlagodir/cordova-plugin-datepicker i used this plugin in my sample app
i am getting date and time picker when first time set the date and time not showing in view if again click the text box it shows previous date and time in view when user click the text box this method will be called $scope.calendarData = function() {
alert(“hi”);

            var options = {
                date: new Date(),
                mode: 'date'
                };
            datePicker.show(options, function(date) {
                var monthName = "";
                switch (date.getMonth()) {
                    case 1:
                        monthName = "Jan";
                        break;
                    case 2:
                        monthName = "Feb";
                        break;
                    case 3:
                        monthName = "Mar";
                        break;
                    case 4:
                        monthName = "Apr";
                        break;
                    case 5:
                        monthName = "May";
                        break;
                    case 6:
                        monthName = "Jun";
                        break;
                    case 7:
                        monthName = "Jul";
                        break;
                    case 8:
                        monthName = "Aug";
                        break;
                    case 9:
                        monthName = "Sept";
                        break;
                    case 10:
                        monthName = "Oct";
                        break;
                    case 11:
                        monthName = "Nov";
                        break;
                    case 12:
                        monthName = "Dec";
                        break;
                }
                var day = "";
                switch (date.getDay()) {
                    case 0:
                        day = "Sun";
                        break;
                    case 1:
                        day = "Mon";
                        break;
                    case 2:
                        day = "Tue";
                        break;
                    case 3:
                        day = "Wed";
                        break;
                    case 4:
                        day = "Thu";
                        break;
                    case 5:
                        day = "Fri";
                        break;
                    case 6:
                        day = "Sat";
                        break;
                }
                $scope.calendar.register = day + ", " + date.getDate() + " " + monthName + " " + date.getFullYear();
                    alert($scope.calendar.startTime);
                var options1 = {
                    date: new Date(),
                    mode: 'time'
                };
                datePicker.show(options1, function(date) {

                    var format;
                    var hours;
                    if (date.getHours() < 12) {
                        hours = date.getHours();
                        format = "AM";
                    } else {
                        hours = date.getHours() - 12;
                        format = "PM";
                    }

                    $scope.register += " " + hours + ":" + date.getMinutes() + " " + format;
                   

                });
            });
        
    };

i binded date and time value to ng-model: $scope.register . here first i am getting time before getting the time i have to select the datepicker. In this situation Can i use call back functions here.How to write call back functions in ionic


#2

this doesn’t appear to be an official plugin, so you may get more/better support from the developer on that github repo


#3

I found quite a few bugs with that DatePicker plugin which I had to fix myself. I use ngCordova btw…

When I fire datepicker my code looks like this:

options = {date: $scope.vm.requestDetails.checkin || new Date(), mode: 'time'}
  $cordovaDatePicker.show(options).then(
    (date) ->
      Utils.safeApply($scope, ->
        $scope.vm.requestDetails.checkinTime = date if isDate(date)
      )
  )

The isDate function is as follows:

isDate = (date) -> Object.prototype.toString.call(date) is '[object Date]' and date.toString() isnt 'Invalid Date'

The safeApply function is as follows:

safeApply: (scope, fn) =>
    if scope.$root?
      phase = scope.$root.$$phase
      if phase is '$apply' or phase is '$digest'
        fn() if (fn && (typeof(fn) is 'function')) 
      else
        scope.$apply fn

Hope that helps