Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 904b455

Browse files
crisbetohansl
authored andcommitted
fix(checkbox): not being marked as checked with ng-checked on load (#9424)
Fixes the checkbox not getting marked as checked on the first load when using `ng-checked`. Fixes #9349
1 parent 3fc1004 commit 904b455

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/components/checkbox/checkbox.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $
109109
}
110110

111111
if (attr.ngChecked) {
112-
scope.$watch(
113-
scope.$eval.bind(scope, attr.ngChecked),
114-
ngModelCtrl.$setViewValue.bind(ngModelCtrl)
115-
);
112+
scope.$watch(scope.$eval.bind(scope, attr.ngChecked), function(value) {
113+
ngModelCtrl.$setViewValue(value);
114+
ngModelCtrl.$render();
115+
});
116116
}
117117

118118
$$watchExpr('ngDisabled', 'tabindex', {

src/components/checkbox/checkbox.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ describe('mdCheckbox', function() {
254254
expect(checkbox.hasClass(CHECKED_CSS)).toBe(false);
255255
});
256256

257+
it('should mark the checkbox as selected on load with ng-checked', function() {
258+
pageScope.isChecked = function() { return true; };
259+
260+
var checkbox = compileAndLink('<md-checkbox ng-model="checked" ng-checked="isChecked()"></md-checkbox>');
261+
262+
expect(checkbox).toHaveClass(CHECKED_CSS);
263+
});
264+
257265
describe('with the md-indeterminate attribute', function() {
258266

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

0 commit comments

Comments
 (0)