-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-timeinput.js
More file actions
40 lines (33 loc) · 1.26 KB
/
angular-timeinput.js
File metadata and controls
40 lines (33 loc) · 1.26 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
angular.module('jquery', [])
.directive('ngTimeInput', function ($parse, $timeout) {
return {
restrict: 'A',
require: 'ngModel',
scope: '=',
link: function (scope, element, attrs, ctrl) {
var optionsFn = $parse(attrs.ngTimeInput);
var initIfNeeded = function () {
if (!element.data('timeInput')) {
element.timeInput(optionsFn(scope));
}
};
ctrl.$formatters.push(function (value) {
initIfNeeded();
element.timeInput('setValue', value);
});
element.on('change', function () {
scope.$apply(function () {
ctrl.$setViewValue(element.val());
});
});
scope.$watch(optionsFn, function (newValue) {
initIfNeeded();
element.timeInput('setOptions', newValue);
}, true);
attrs.$observe('tabindex', function (newValue) {
element.timeInput('setTabindex', newValue);
});
initIfNeeded();
}
}
});