I have spent sometime on researching the existing datetime directives of angularjs.
Both ngularUI and AngularStrap do not provide a datetimepicker as I needed. Of co
I had the same issue. Here's what I ended up doing that worked well for me:
'use strict';
angular.module('frontStreetApp.directives')
.directive('psDatetimePicker', function (moment) {
var format = 'MM/DD/YYYY hh:mm A';
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attributes, ctrl) {
element.datetimepicker({
format: format
});
var picker = element.data("DateTimePicker");
ctrl.$formatters.push(function (value) {
var date = moment(value);
if (date.isValid()) {
return date.format(format);
}
return '';
});
element.on('change', function (event) {
scope.$apply(function() {
var date = picker.getDate();
ctrl.$setViewValue(date.valueOf());
});
});
}
};
});
Here's the HTML:
<!-- The dueDate field is a UNIX offset of the date -->
<input type="text"
ng-model="dueDate"
ps-datetime-picker
class="form-control">
You can check out the gists and a bit more information in my blog post.