Search code examples
angularjscordovaionic-frameworkngcordova

ionic Date time picker show only the date (ng-cordova)


i'm working with ionic framework to develop a web app . in this app i need a datetime picker so i instaled ng-cordova datepicker plugin , on android device it's works good but on ios device i get only the date without the time here is my code :

var options_date = {
 date: new Date(),
 mode: 'datetime', // or 'time'
 minDate: new Date() - 10000,
 allowOldDates: true,
 allowFutureDates: true,
 doneButtonLabel: 'DONE',
 doneButtonColor: '#F2F3F4',
 cancelButtonLabel: 'CANCEL',
 cancelButtonColor: '#000000'
};
$scope.setDate = function() {
  $cordovaDatePicker.show(options_date).then(function(date){
     $scope.startDateTime = date;
  });
};

thanks for your help


Solution

  • can you check with this code it is working for me:
    In index.html create a button as

    <ion-content ng-controller="ExampleCtrl">
          <button class="button button-bar button-balanced" ng-click="datePick()">Check It</button>
          </ion-content>
    

    In your controller write the function code as:

    .controller('ExampleCtrl', ['$scope','$ionicPlatform','$cordovaDatePicker', function ($scope,$ionicPlatform,$cordovaDatePicker) {
      $scope.datePick = function(){
        var options = {
        date: new Date(),
        mode: 'datetime', // or 'time'
        minDate: new Date() - 10000,
        allowOldDates: true,
        allowFutureDates: false,
        doneButtonLabel: 'DONE',
        doneButtonColor: '#F2F3F4',
        cancelButtonLabel: 'CANCEL',
        cancelButtonColor: '#000000'
    
        }
        $ionicPlatform.ready(function(){
          $cordovaDatePicker.show(options).then(function(date){
            alert(date);
          });
    
        })
      }
    
    }])