angular-moment-picker

Angular Moment Picker

Join the chat at https://gitter.im/indrimuska/angular-moment-picker NPM version NPM downloads MIT License

Check out the homepage at http://indrimuska.github.io/angular-moment-picker/.

Angular Moment Picker is a native AngularJS directive for date and time picker that uses Moment.js and does not require jQuery.

Angular Moment Picker Demo

Installation

Get Angular Moment Picker from npm, bower or git:

npm install angular-moment-picker

bower install moment-picker

git clone https://github.com/indrimuska/angular-moment-picker.git

Include style and script in your page:

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"></script>

<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment-with-locales.js></script>

<script src="//cdn.rawgit.com/indrimuska/angular-moment-picker/master/dist/angular-moment-picker.min.js"></script>

<link href="//cdn.rawgit.com/indrimuska/angular-moment-picker/master/dist/angular-moment-picker.min.css" rel="stylesheet">

Add moment-picker dependency to your module:

var myApp = angular.module('myApp', ['moment-picker']);

Provide the attribute to your element:

<div moment-picker="myDate"> {{ myDate }} </div>

Demo

Check out the demo page at http://indrimuska.github.io/angular-moment-picker/.

The views

Decade view

Year view

Month view

Day view

Hour view

Minute view

Options

To configure Angular Moment Picker you have to append to your block or your input the attribute options you want to set.

html

<div moment-picker="ctrl.birthday" locale="fr" format="LL">

Mon anniversaire est le {{ ctrl.birthday }}

</div>

moment-picker: Two-way bindable property as formatted datetime string.

ng-model: Two-way bindable property as Moment.js object.

locale - default "en": Locale code. 1

format - default "L LTS": Format of the output value and min/max date. 1

min-view - default "decade": Minimum navigable view.

max-view - default "minute": Maximum navigable view.

start-view - default "year": Initial view when the picker is open.

min-date: Two-way bindable property representing the minimum selectable date (as String in the same format of the value, or as a Moment.js object).

max-date: Two-way bindable property representing the maximum selectable date (as String in the same format of the value, or as a Moment.js object).

start-date: Two-way bindable property representing the initial date to be shown in picker (as String in the same format of the value, or as a Moment.js object).

disable - default false: Disables the picker if truly.

validate - default true: Forces picker value between the range minDate and maxDate.

autoclose - default true: Closes the picker after selecting a date.

today - default false: Highlights the current day.

keyboard - default false: Allows using the keyboard to navigate the picker.

additions - default { top: undefined, bottom: undefined }: Template url for custom contents above and below each picker views (inside the dialog).

Events

As for the options, to bind an event you only need to append the right property to your picker.

html

<div moment-picker="ctrl.meeting" format="HH:mm A" change="ctrl.onChange(newValue, oldValue)">

The meeting starts at {{ ctrl.meeting }}.

</div>

change(newValue, oldValue): Function fired upon change in picker value.

momentPickerProvider

Angular Moment Picker comes out with its own provider, in order to define your own configuration for all the pickers in your app.

javascript

angular

.module('myApp', ['moment-picker'])

.config(['momentPickerProvider', function (momentPickerProvider) {

momentPickerProvider.options({

/* ... */

});

}]);

locale - default "en": Locale code. 1

format - default "L LTS": Format of the output value and min/max date. 1

min-view - default "decade": Minimum navigable view.

max-view - default "hour": Maximum navigable view.

start-view - default "year": Initial view when opening the picker.

left-arrow - default "&larr;": Left arrow string (HTML allowed).

right-arrow - default "&rarr;": Right arrow string (HTML allowed).

years-format - default "YYYY": Years format in decade view.

months-format - default "MMM": Months format in year view.

days-format - default "D": Days format in month view.

hours-format - default "HH:[00]": Hours format in day view.

minutes-format - default 2: Minutes format in hour view.

minuts-step - default 5: Step between each visible minute in hour view.

seconds-format - default "ss": Seconds format in minute view.

seconds-step - default 1: Step between each visible second in minute view.

Notes

  1. Locale codes and format tokens are available at http://momentjs.com/.

  2. Locale format LT without meridiem part (AM/PM, am/pm).

Builder

Try the online Angular Moment Picker Builder:

http://indrimuska.github.io/angular-moment-picker/#builder.

License

Copyright (c) 2015 Indri Muska. Licensed under the MIT license.

comments powered by Disqus
This page was last updated 5 months ago.