mgcrea.ngStrap.timepicker
Add quick, dynamic timepicker functionality with any form text input.
Timepickers require the tooltip module and dateParser helper module to be loaded.
Theses docs currently use bootstrap-additions for styling purposes.
This module leverages the $locale service. You just have to load the proper i18n file to seamlessly translate your timepickers.
$scope.time = {{time}}; // (formatted: {{time | date:'shortTime'}}) $scope.selectedTimeAsNumber = {{selectedTimeAsNumber}}; // (formatted: {{selectedTimeAsNumber | date:'shortTime'}}) $scope.sharedDate = {{sharedDate}}; // (formatted: {{sharedDate | date:'short'}})
Append a
bs-timepicker
attribute to any element to enable the directive.
$timepicker
serviceAvailable for programmatic use (mainly in directives as it requires a DOM element).
var myTimepicker = $timepicker(element, ngModelController);
Options can be passed via data-attributes on the directive or as an object hash to configure the service. For data attributes,
append the option name to
data-
, as in
data-animation=""
.
You can position your select in corners (such as
bottom-left
) or any other combination two.
Exotic placement options are not part of the Bootstrap's core, to use them you must use
bootstrap-additions.css
from the
BootstrapAdditions project. This project being not yet fully released, meanwhile, you can use the
development snapshot compiled for theses docs.
Name | type | default | description |
---|---|---|---|
animation | string | am-fade | apply a CSS animation powered by
ngAnimate
|
placement | string | 'bottom-left' |
how to position the timepicker - top | bottom | left | right | auto, or any combination like bottom-left or auto bottom-left.
When "auto" is specified, it will dynamically reorient the timepicker. For example, if placement is "auto left", the timepicker will display to the left when possible, otherwise it will display right. |
trigger | string | 'focus' | how timepicker is triggered - click | hover | focus | manual |
html | boolean | false | replace
ng-bind with
ng-bind-html , requires
ngSanitize to be loaded |
delay | number | object | 0 |
delay showing and hiding the timepicker (ms) - does not apply to manual trigger type If a number is supplied, delay is applied to both hide/show Object structure is:
|
container | string | false | false |
Appends the timepicker to a specific element. Example:
|
template | path | id | '$timepicker' |
If provided, overrides the default template, can be either a remote URL or a cached template id. |
onShow | function |
If provided, this function will be invoked after the timepicker is shown. |
|
onBeforeShow | function |
If provided, this function will be invoked before the timepicker is shown. |
|
onHide | function |
If provided, this function will be invoked after the timepicker is hidden. |
|
onBeforeHide | function |
If provided, this function will be invoked before the timepicker is hidden. |
|
timeFormat | string | 'shortTime' |
Rendering format of your time, leverages ng.filter:date. |
modelTimeFormat | string | null |
Model format of your time, leverages ng.filter:date. |
timeType | string | 'date' |
Expected model type of your time - date | number | unix | iso | string If type is "number" then timepicker uses milliseconds to set date, if "unix" - seconds |
autoclose | boolean | false |
Whether the picker should close itself upon select. |
useNative | boolean | true |
Whether to use a native component if available (iOS/Android). |
minTime | date* | -Infinity |
Minimum allowed time for selection (parsed against current format). You can use the string "now" that will resolve the current time. |
maxTime | date* | +Infinity |
Maximum allowed time for selection (parsed against current format). You can use the string "now" that will resolve the current time. |
length | number | 5 |
Length of the timepicker (should be an odd number). |
hourStep | number | 1 |
Default step for hours. |
minuteStep | number | 5 |
Default step for minutes. |
secondStep | number | 5 |
Default step for seconds. |
roundDisplay | boolean | false |
Whether the picker should round the minute values displayed when no initial time is specified. The rounding is made by dividing time in minuteStep intervals and flooring the current time to the nearest. |
iconUp | string | 'glyphicon glyphicon-chevron-up' |
CSS class for 'up' icon. |
iconDown | string | 'glyphicon glyphicon-chevron-down' |
CSS class for 'down' icon. |
arrowBehavior | string | 'pager' |
Sets the behavior of the arrow buttons in the picker. 'pager' to move the displayed hour/minute options, 'picker' to change the current time hours/minutes value. |
defaultDate | string | 'auto' |
Sets default date for timepicker + datepicker if date is not selected yet. You can use the string 'today' to set today, or 'auto' to set 01.01.1970. |
You can override global defaults for the plugin with
$timepickerProvider.defaults
angular.module('myApp')
.config(function($timepickerProvider) {
angular.extend($timepickerProvider.defaults, {
timeFormat: 'HH:mm',
length: 7
});
})