ionic日期时间选择器只显示日期(ng-cordova)



我正在与ionic框架开发一个web应用程序。在这个应用中,我需要一个日期时间选择器,所以我安装了ng-cordova日期选择器插件,在android设备上它工作得很好,但在ios设备上,我只得到日期而没有时间,这是我的代码:

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;
  });
};

谢谢你的帮助

你能检查一下这个代码是否为我工作吗?
在index.html中创建一个按钮

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

在你的控制器中写函数代码:

.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);
      });
    })
  }
}])

Android浏览器暂时不支持datetime HTML5输入类型。

插件的README页面也说datetime只适用于iOs和Windows。

可以使用

mode: 'date'

mode: 'time'

最新更新