-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenhancedCheckNgModule.js
41 lines (31 loc) · 1.18 KB
/
enhancedCheckNgModule.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
36
37
38
39
40
41
(function () {
'use strict';
var enchancedCheckModule = angular.module('ui.enhancedCheck', []);
enchancedCheckModule.directive('enhancedCheckToggle', function() {
return {
restrict: 'C',
require: ['ngModel'],
scope: {
bindModel: '=ngModel',
bindDisabled: '=ngDisabled',
},
link: function(scope, element, attributes, controllers) {
var ngModelController = controllers[0];
scope.$watch("bindModel", function() {
var disabled = scope.bindDisabled;
if(disabled) {
element.bootstrapToggle('enable');
}
element.trigger('change.toggle');
if(disabled) {
element.bootstrapToggle('disable');
}
});
element.on('change.toggle', function(event) {
var checked = element.prop('checked');
ngModelController.$setViewValue(checked);
});
}
}
});
})();