-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathangular-bootstrap-datetimepicker-directive.js
More file actions
52 lines (52 loc) · 1.85 KB
/
Copy pathangular-bootstrap-datetimepicker-directive.js
File metadata and controls
52 lines (52 loc) · 1.85 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
angular
.module('datetimepicker', [])
.provider('datetimepicker', function() {
var default_options = {};
this.setOptions = function(options) {
default_options = options;
};
this.$get = function() {
return {
getOptions: function() {
return default_options;
}
};
};
})
.directive('datetimepicker', [
'$timeout',
'datetimepicker',
function($timeout,
datetimepicker) {
var default_options = datetimepicker.getOptions();
return {
require: '?ngModel',
restrict: 'AE',
scope: {
datetimepickerOptions: '@'
},
link: function($scope, $element, $attrs, ngModelCtrl) {
var passed_in_options = $scope.$eval($attrs.datetimepickerOptions);
var options = jQuery.extend({}, default_options, passed_in_options);
$element
.on('dp.change', function(e) {
if (ngModelCtrl) {
$timeout(function() {
ngModelCtrl.$setViewValue(e.target.value);
});
}
})
.on('dp.show', function (e) {
var that = this;
if (ngModelCtrl) {
$timeout(function() {
$(that).data("DateTimePicker").date(e.target.value);
});
}
})
.datetimepicker(options);
}
};
}
]);