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

Commit

Permalink
fix(checkbox): ngModel intial value used correctly with events
Browse files Browse the repository at this point in the history
Fixes #1550.
  • Loading branch information
ThomasBurleson committed Apr 12, 2015
1 parent ba49edc commit 942d0b9
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/components/checkbox/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
* @name material.components.checkbox
* @description Checkbox module!
*/
angular.module('material.components.checkbox', [
'material.core'
])
angular
.module('material.components.checkbox', ['material.core'])
.directive('mdCheckbox', MdCheckboxDirective);

/**
Expand Down Expand Up @@ -78,7 +77,6 @@ function MdCheckboxDirective(inputDirective, $mdInkRipple, $mdAria, $mdConstant,

return function postLink(scope, element, attr, ngModelCtrl) {
ngModelCtrl = ngModelCtrl || $mdUtil.fakeNgModel();
var checked = false;
$mdTheming(element);

if (attr.ngChecked) {
Expand Down Expand Up @@ -112,15 +110,14 @@ function MdCheckboxDirective(inputDirective, $mdInkRipple, $mdAria, $mdConstant,
if (element[0].hasAttribute('disabled')) return;

scope.$apply(function() {
checked = !checked;
ngModelCtrl.$setViewValue(checked, ev && ev.type);
// Toggle the checkbox value...
ngModelCtrl.$setViewValue( !ngModelCtrl.$viewValue, ev && ev.type);
ngModelCtrl.$render();
});
}

function render() {
checked = ngModelCtrl.$viewValue;
if(checked) {
if(ngModelCtrl.$viewValue) {
element.addClass(CHECKED_CSS);
} else {
element.removeClass(CHECKED_CSS);
Expand Down

0 comments on commit 942d0b9

Please sign in to comment.