本文转自:https://market.ionic.io/plugins/ionicdatepicker

##Introduction:

This is an ionic-datepicker bower component, which can be used in any Ionic framework's application. No additional plugins required for this component.

View Demo

##Prerequisites.

  • node.js
  • npm
  • bower
  • gulp

##How to use:

1) In your project repository install the ionic-datepicker using bower

bower install ionic-datepicker --save

This will install the latest version released.

2) Give the path of  ionic-datepicker.bundle.min.js in your index.html file.

<!-- path to ionic/angularjs -->
<script src="lib/ionic-datepicker/dist/ionic-datepicker.bundle.min.js"></script>

3) In your application module inject the dependency ionic-datepicker, in order to work with the ionic time picker

angular.module('mainModuleName', ['ionic', 'ionic-datepicker']){
//
}

4) Use the below format in your template's corresponding controller

    $scope.datepickerObject = {
titleLabel: 'Title', //Optional
todayLabel: 'Today', //Optional
closeLabel: 'Close', //Optional
setLabel: 'Set', //Optional
setButtonType : 'button-assertive', //Optional
todayButtonType : 'button-assertive', //Optional
closeButtonType : 'button-assertive', //Optional
inputDate: new Date(), //Optional
mondayFirst: true, //Optional
disabledDates: disabledDates, //Optional
weekDaysList: weekDaysList, //Optional
monthList: monthList, //Optional
templateType: 'popup', //Optional
showTodayButton: 'true', //Optional
modalHeaderColor: 'bar-positive', //Optional
modalFooterColor: 'bar-positive', //Optional
from: new Date(2012, 8, 2), //Optional
to: new Date(2018, 8, 25), //Optional
callback: function (val) { //Mandatory
datePickerCallback(val);
}
dateFormat: 'dd-MM-yyyy', //Optional
closeOnSelect: false, //Optional
};

$scope.datepickerObject is the main object, that we need to pass to the directive. The properties of this object are as follows.

a) titleLabel(Optional) : The label for 'Title' of the ionic-datepicker popup. Default value is Select Date

b) todayLabel(Optional) : The label for Today button. Default value is Today

c) closeLabel(Optional) : The label for Close button. Default value is Close

d) setLabel(Optional) : The label for Set button. Default value is Set

e) setButtonType(Optional) : This the type of the Set button. Default value is button-positive. You can give any valid ionic framework's button classes.

f) todayButtonType(Optional) : This the type of the Today button. Default value is button-stable. You can give any valid ionic framework's button classes.

g) closeButtonType(Optional) : This the type of the Close button. Default value is button-stable. You can give any valid ionic framework's button classes.

h) inputDate(Optional) : This is the date object to pass to the directive. You can give any date object to this property. Default value is new Date(). But if you wish to show the initial date in the HTML page, then you should define this property.

i) mondayFirst(Optional) : Set true if you wish to show monday as the first day. Default value is false.

j) disabledDates(Optional) : If you have a list of dates to disable, you can create an array like below. Default value is an empty array.

var disabledDates = [
new Date(1437719836326),
new Date(),
new Date(2015, 7, 10), //months are 0-based, this is August, 10th!
new Date('Wednesday, August 12, 2015'), //Works with any valid Date formats like long format
new Date("08-14-2015"), //Short format
new Date(1439676000000) //UNIX format
];

k) weekDaysList(Optional) : This is an array with a list of all week days. You can use this if you want to show months in some other language or format or if you wish to use the modal instead of the popup for this component (Refer to point l), you can define the weekDaysList array in your controller as shown below.

 var weekDaysList = ["Sun", "Mon", "Tue", "Wed", "thu", "Fri", "Sat"];

The default values are

 ["S", "M", "T", "W", "T", "F", "S"];

l) monthList(Optional) : This is an array with a list of all months. You can use this if you want to show months in some other language or format. You can create an array like below.

 var monthList = ["Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];

The default values are

 ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

m) templateType(Optional) : This is string type which takes two values i.e. modal or popup. Default value is modal. If you wish to open in a popup, you can specify the value as popup or else you can ignore it.

n) modalHeaderColor(Optional) : This takes any valid ionic framework's header color. Default value is bar-stable

o) modalFooterColor(Optional) : This takes any valid ionic framework's footer color. Default value is bar-stable

p) from(Optional) : This is a date object, from which you wish to enable the dates. You can use this property to disable previous dates by specifying from: new Date(). By default all the dates are enabled. Please note that months are 0 based.

q) to(Optional) : This is a date object, to which you wish to enable the dates. You can use this property to disable future dates by specifying to: new Date(). By default all the dates are enabled. Please note that months are 0 based.

r) callback(Mandatory) : This the callback function, which will get the selected date in to the controller. You can define this function as follows.

var datePickerCallback = function (val) {
if (typeof(val) === 'undefined') {
console.log('No date selected');
} else {
console.log('Selected date is : ', val)
}
};

s) dateFormat(Optional) : This is date format used in template. Defaults to dd-MM-yyyy. For how to format date, see: http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15

t) closeOnSelect(Optional) : Boolean to indicate wheteher datepicker will be closed after date selection. If set to true, "Set" button will be hidden. Defaults to false.

5) Then use the below format in your template / html file

<ionic-datepicker input-obj="datepickerObject">
<button class="button button-block button-positive"> {{datepickerObject.inputDate | date:'dd - MMMM - yyyy'}}</button>
</ionic-datepicker>

a) ionic-datepicker is the directive, to which we can pass required vales.

b) input-obj(Mandatory) : This is an object. We have to pass an object as shown above.

##Screen Shots:

Once you are successfully done with the above steps, you should be able to see the below screen shots. I have used two buttons here.

The first screen shot shows only the buttons before clicking on them. Once you click on the button you should see the second screen shot.

[转]Ionic Datepicker的更多相关文章

  1. ionic第二坑——ionic 上拉菜单(ActionSheet)安卓样式坑

    闲话不说,先上图: 这是IOS上的显示效果,代码如下: HTML部分: <body ng-app="starter" ng-controller="actionsh ...

  2. ionic第一坑——ion-slide-box坑(ion-slide分两页的坑)

    ionic.views.Slider = ionic.views.View.inherit({ initialize: function (options) { . . . function setu ...

  3. ionic之$ionicGesture手势(大坑)

    鄙人来本公司前未用过ionic框架,但由于ionic是基于angularjs封装的,正好我用过angularjs,很荣幸的面试就过了,然后通过该网站http://www.ionic.wang(后面简称 ...

  4. Windows Phone Toolkit 的 DatePicker 控件本地化的问题

    用到 The Windows Phone Toolkit 里的 DatePicker 控件,但是多语言的时候出现了问题: 手机设置为中文,虽然月份跟星期有效,但是 Title 却还是默认的语言:CHO ...

  5. Ionic2系列——Ionic 2 Guide 官方文档中文版

    最近一直没更新博客,业余时间都在翻译Ionic2的文档.之前本来是想写一个入门,后来觉得干脆把官方文档翻译一下算了,因为官方文档就是最好的入门教程.后来越翻译越觉得这个事情确实比较费精力,不知道什么时 ...

  6. Win10 UWP开发系列:使用VS2015 Update2+ionic开发第一个Cordova App

    安装VS2015 Update2的过程是非常曲折的.还好经过不懈的努力,终于折腾成功了. 如果开发Cordova项目的话,推荐大家用一下ionic这个框架,效果还不错.对于Cordova.PhoneG ...

  7. Ionic 简单操作

    在使用 Ionic 之前要安装 Nodejs,Cordova . Java 下载Java 网站.Java 默认安装在 C:\Program Files\Java 文件目录. Android 下载And ...

  8. 【初探IONIC】不会Native可不可以开发APP?

    前言 Hybrid技术流行已经有一段日子了,楼主的关注点也一直围绕着移动端围绕着Hybrid相关展开,Hybrid已经是大大提升开发效率的开发方式了,但是仍然需要至少一个IOS与Andriod,那么可 ...

  9. 一个简单移动页面ionic打包成app

    先贴JS代码好了,缓动和调整透明度的功能,最后用ionic打包成应用就可以 window.onload=function(){ search(); move(); calc();}function s ...

随机推荐

  1. 如何弹出一定的大小的web窗体?

    如何弹出一定的大小的web窗体?  摘自: http://blog.163.com/hweibin126@126/blog/static/17044246920108413348344/ 一.wind ...

  2. 如何提高码农产量,基于ASP.NET MVC的敏捷开发框架开发随笔一

    公司业务量比较大,接了很多项目,为了缩短开发周期老板让我牵头搭建了一个敏捷开发框架. 我们主要的业务是做OA.CRM.ERP一类的管理系统,一个通用的后台搭出来,再配合一些快速开发的组件开发效率能提高 ...

  3. 重新想象 Windows 8 Store Apps (63) - 通信: WebSocket

    [源码下载] 重新想象 Windows 8 Store Apps (63) - 通信: WebSocket 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 通信 So ...

  4. android 学习资料

    Fragment 事件分发机制 事件分发机制2 NDK JNI ndk { moduleName "mymodule" ldLibs "log" stl &qu ...

  5. JavaMail入门第三篇 发送邮件

    JavaMail API中定义了一个java.mail.Transport类,它专门用于执行邮件发送任务,这个类的实例对象封装了某种邮件发送协议的底层实施细节,应用程序调用这个类中的方法就可以把Mes ...

  6. FL2440驱动添加(5)ADC驱动学习笔记

    由图可知,模拟ADC分为两部分功能,一部分是触屏功能,另一部分就是普通ADC功能.分别可以产生INT_TC和INT_ADC 两个中断.该ADC模块总共有8个通道可以进行模拟信号的输入,分别是AIN0. ...

  7. linux服务开机启动顺序

    今天遇到了一个问题,我们写了一个服务脚本A,该服务需要优先于mysql启动.脚本是从其他地方拷来的模板,前面的默认配置没改,只是实现了自己的功能.写完,chkconfig A on,reboot,启动 ...

  8. [moka同学摘录]Yii2 csv数据导出扩展

    yii2-thecsv(Yii2框架csv数据导出扩展) github: https://github.com/13552277443/yii2-thecsv 1.安装 运行 php composer ...

  9. rabbitmq队列中消息过期配置

    最近公司某个行情推送的rabbitmq服务器由于客户端异常导致rabbitmq队列中消息快速堆积,还曾导致过内存积压导致rabbitmq客户端被block的情况.考虑到行情信息从业务上来说可以丢失部分 ...

  10. js中创建对象的几种方式

    创建对象指创建一个object并给这个对象添加属性和方法,有以下几个方式: 最基本的: var Person={}; Person.name='tom'; Person.age='20'; Perso ...