-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular-datepicker.js
35 lines (34 loc) · 1.14 KB
/
angular-datepicker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
angular.module('$datePicker', []).directive('datePicker', function() {
return {
restrict: "A",
require: "?ngModel",
link: function(scope, element, attrs, ngModel) {
element.bind('blur keyup change', function(){
scope.$apply(function() {
ngModel.$setViewValue(element.val());
});
});
element.bind('click', function(){
if (element.attr("datePicker-inited") != 'true') {
element.datepicker({
format: "yyyy-mm-dd",
endDate: "today",
todayBtn: "linked",
language: "zh-CN",
multidate: false,
autoclose: true,
keyboardNavigation: false,
todayHighlight: true
});
element.attr("datePicker-inited", 'true');
element.datepicker('show');
}
});
scope.$watch(attrs.ngModel, function(newValue, oldValue) {
if (newValue) {
element.val(newValue);
}
}, true);
}
};
});