Created
December 8, 2014 18:53
-
-
Save cdmckay/9328730990b9a4ed58d6 to your computer and use it in GitHub Desktop.
Angular directive for eonasdan's Bootstrap DateTime picker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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()); | |
}); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment