Skip to content

Instantly share code, notes, and snippets.

@jkresner
Created August 10, 2015 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkresner/7a81a1882452966f16ce to your computer and use it in GitHub Desktop.
Save jkresner/7a81a1882452966f16ce to your computer and use it in GitHub Desktop.
<div class="dropdown">
<a id="{{id}}" class="dropdown-toggle {{id}}"
role="button" data-toggle="dropdown" data-target="#" href="#">
<div class="input-group">
<input type="text" class="form-control" value="{{datetime.format(dateFormat)}}">
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</a>
<ul ng-if="minView" class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<datetimepicker data-ng-model="datetime"
data-datetimepicker-config="{ minView:'{{minView}}', startView:'{{startView}}', minuteStep: {{minuteStep}} }"
data-on-set-time="onSetTime(newDate, oldDate)"></datetimepicker>
</ul>
</div>
.directive('datetimeInput', function() {
return {
restrict: 'EA',
template: require('./datetimepicker.html'),
scope: {
datetime: '=datetime',
setCallback: '=setCallback'
},
link: function(scope, element, attrs) {
scope.id = attrs.id
scope.minView = attrs.minView || 'day'
scope.startView = attrs.startView || 'day'
scope.minuteStep = attrs.minuteStep || 30
scope.dateFormat = attrs.dateFormat || 'YYYY MMM DD'
},
controller: function($scope, $element, $attrs) {
$scope.onSetTime = (newDate, oldDate) => {
if ($scope.setTimeCallback)
scope.setTimeCallback(newDate, oldDate)
$element.find('.dropdown').removeClass('open')
$scope.datetime = moment(newDate)
}
}
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment