Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/components/checkbox/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $

if (attr.ngChecked) {
scope.$watch(
scope.$eval.bind(scope, attr.ngChecked),
ngModelCtrl.$setViewValue.bind(ngModelCtrl)
scope.$eval.bind(scope, attr.ngChecked),
ngModelCtrl.$setViewValue.bind(ngModelCtrl)
);
}

Expand Down Expand Up @@ -186,7 +186,8 @@ function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $
}

function render() {
element.toggleClass('md-checked', ngModelCtrl.$viewValue && !isIndeterminate);
// Cast the $viewValue to a boolean since it could be undefined
element.toggleClass('md-checked', !!ngModelCtrl.$viewValue && !isIndeterminate);
}

function setIndeterminateState(newValue) {
Expand All @@ -196,6 +197,6 @@ function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $
}
element.toggleClass('md-indeterminate', isIndeterminate);
}
};
}
}
}
6 changes: 6 additions & 0 deletions src/components/checkbox/checkbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ describe('mdCheckbox', function() {
expect(checkbox.hasClass('ng-invalid')).toBe(true);
});

it('properly unsets the md-checked CSS if ng-checked is undefined', function() {
var checkbox = compileAndLink('<md-checkbox ng-checked="value"></md-checkbox>');

expect(checkbox.hasClass(CHECKED_CSS)).toBe(false);
});

describe('with the md-indeterminate attribute', function() {

it('should set md-indeterminate attr to true by default', function() {
Expand Down