diff --git a/js/angular/directive/checkbox.js b/js/angular/directive/checkbox.js
index 5b9c8af3d11..2492b288b72 100644
--- a/js/angular/directive/checkbox.js
+++ b/js/angular/directive/checkbox.js
@@ -21,30 +21,30 @@ IonicModule
restrict: 'E',
replace: true,
require: '?ngModel',
- scope: {
- ngModel: '=?',
- ngValue: '=?',
- ngChecked: '=?',
- ngDisabled: '=?',
- ngChange: '&'
- },
transclude: true,
-
template: '',
-
compile: function(element, attr) {
var input = element.find('input');
- if(attr.name) input.attr('name', attr.name);
- if(attr.ngChecked) input.attr('ng-checked', attr.ngChecked);
- if(attr.ngDisabled) input.attr('ng-disabled', attr.ngDisabled);
- if(attr.ngTrueValue) input.attr('ng-true-value', attr.ngTrueValue);
- if(attr.ngFalseValue) input.attr('ng-false-value', attr.ngFalseValue);
+ forEach({
+ 'name': attr.name,
+ 'ng-value': attr.ngValue,
+ 'ng-model': attr.ngModel,
+ 'ng-checked': attr.ngChecked,
+ 'ng-disabled': attr.ngDisabled,
+ 'ng-true-value': attr.ngTrueValue,
+ 'ng-false-value': attr.ngFalseValue,
+ 'ng-change': attr.ngChange
+ }, function(value, name) {
+ if (isDefined(value)) {
+ input.attr(name, value);
+ }
+ });
}
};
diff --git a/test/html/toggle.html b/test/html/toggle.html
index 7b1b7f78edc..5a2c78a5034 100644
--- a/test/html/toggle.html
+++ b/test/html/toggle.html
@@ -17,6 +17,12 @@
Toggle
+
+ Main Check
+
+
+ Follows ng-change of Main Check
+
myModel ({{!!myModel}})
Cats or dogs? ({{catModel}})
Disable myModel ({{!!isDisabled}})
diff --git a/test/unit/angular/directive/checkbox.unit.js b/test/unit/angular/directive/checkbox.unit.js
index 5357faf17fc..75e12db756d 100644
--- a/test/unit/angular/directive/checkbox.unit.js
+++ b/test/unit/angular/directive/checkbox.unit.js
@@ -28,13 +28,28 @@ describe('Ionic Checkbox', function() {
});
it('should pass down attrs', function() {
- el = compile('')(scope);
+ el = compile('')(scope);
scope.$apply();
var input = el.find('input');
- expect(input.attr('ng-checked')).toBe('1');
- expect(input.attr('ng-disabled')).toBe('2');
- expect(input.attr('ng-true-value')).toBe('3');
- expect(input.attr('ng-false-value')).toBe('4');
+ expect(input.attr('name')).toBe('name');
+ expect(input.attr('ng-model')).toBe('model');
+ expect(input.attr('ng-checked')).toBe('checked');
+ expect(input.attr('ng-disabled')).toBe('disabled');
+ expect(input.attr('ng-true-value')).toBe('true-value');
+ expect(input.attr('ng-false-value')).toBe('false-value');
+ expect(input.attr('ng-change')).toBe('change');
+ });
+
+ it('shouhld ngChecked properly', function() {
+ el = compile('')(scope);
+ scope.$apply();
+ var input = el.find('input');
+ expect(input[0].hasAttribute('checked')).toBe(false);
+ scope.$apply('shouldCheck = true');
+ expect(input[0].hasAttribute('checked')).toBe(true);
+ scope.$apply('shouldCheck = false');
+ expect(input[0].hasAttribute('checked')).toBe(false);
+
});
});