Skip to content

Instantly share code, notes, and snippets.

@markovic131
Created February 7, 2014 12:54
Show Gist options
  • Save markovic131/8862174 to your computer and use it in GitHub Desktop.
Save markovic131/8862174 to your computer and use it in GitHub Desktop.
AngularJS Directive : Bootstrap 3 DatePicker
myApp.directive('datePicker', function() {
return {
restrict: 'E',
require: ['ngModel'],
scope: {
ngModel: '='
},
replace: true,
template: '<input type="text" id="datePicker" class="form-control" ngModel>',
link: function(scope, element, attrs) {
scope.ngModel = moment().format('YYYY-MM-DD');
element.datetimepicker({
format: "YYYY-MM-DD",
showMeridian: false,
autoclose: true,
pickTime : false
});
element.bind('blur keyup change click changeDate', function() {
scope.ngModel = element.val();
});
}
}
});
@markovic131
Copy link
Author

Requires: momentjs (http://momentjs.com) or remove line 12 if you don't want default date of today.

Usage:

<date-picker ng-model="myDate"></date-picker>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment