Created
October 25, 2017 12:32
-
-
Save cuonggt/e2633b25f992cb38903e5e09c25697b3 to your computer and use it in GitHub Desktop.
AngularJS directive for Bootstrap datepicker
This file contains 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
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