Created
February 7, 2014 12:54
-
-
Save markovic131/8862174 to your computer and use it in GitHub Desktop.
AngularJS Directive : Bootstrap 3 DatePicker
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
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(); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires: momentjs (http://momentjs.com) or remove line 12 if you don't want default date of today.
Usage: