Skip to content

Instantly share code, notes, and snippets.

@cuonggt
Created October 25, 2017 12:32
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 cuonggt/e2633b25f992cb38903e5e09c25697b3 to your computer and use it in GitHub Desktop.
Save cuonggt/e2633b25f992cb38903e5e09c25697b3 to your computer and use it in GitHub Desktop.
AngularJS directive for Bootstrap datepicker
angular
.module('directives.abDatepicker', [])
.directive('abDatepicker', abDatepicker);
abDatepicker.$inject = [];
/* @ngInject */
function abDatepicker() {
return {
require: 'ngModel',
restrict: 'A',
link: function (scope, element, attrs, ngModelCtrl) {
$(element).datepicker({
format: 'dd/mm/yyyy'
}).on('changeDate', function (e) {
ngModelCtrl.$setViewValue(moment(e.date).format('DD/MM/YYYY'));
scope.$apply();
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment