From 2680cf1565afb4a8858737f0201933a400b9059e Mon Sep 17 00:00:00 2001 From: Thomas Burleson Date: Mon, 13 Apr 2015 11:11:38 -0500 Subject: [PATCH] fix(checkbox): support for ng-checked Added support and demo for ng-checked usages. Fixes #1550. --- src/components/checkbox/checkbox.js | 4 ++- .../checkbox/demoBasicUsage/index.html | 3 +- .../checkbox/demoSyncing/index.html | 30 +++++++++++++++++++ src/components/checkbox/demoSyncing/script.js | 18 +++++++++++ src/components/checkbox/demoSyncing/style.css | 26 ++++++++++++++++ 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/components/checkbox/demoSyncing/index.html create mode 100644 src/components/checkbox/demoSyncing/script.js create mode 100644 src/components/checkbox/demoSyncing/style.css diff --git a/src/components/checkbox/checkbox.js b/src/components/checkbox/checkbox.js index 67ab925795d..0a256df471f 100644 --- a/src/components/checkbox/checkbox.js +++ b/src/components/checkbox/checkbox.js @@ -111,7 +111,9 @@ function MdCheckboxDirective(inputDirective, $mdInkRipple, $mdAria, $mdConstant, scope.$apply(function() { // Toggle the checkbox value... - ngModelCtrl.$setViewValue( !ngModelCtrl.$viewValue, ev && ev.type); + var viewValue = attr.ngChecked ? attr.checked : !ngModelCtrl.$viewValue; + + ngModelCtrl.$setViewValue( viewValue, ev && ev.type); ngModelCtrl.$render(); }); } diff --git a/src/components/checkbox/demoBasicUsage/index.html b/src/components/checkbox/demoBasicUsage/index.html index e8d42e65283..055138fe86d 100644 --- a/src/components/checkbox/demoBasicUsage/index.html +++ b/src/components/checkbox/demoBasicUsage/index.html @@ -1,5 +1,6 @@ -
+
+

Using ngModel:

Checkbox 1: {{ data.cb1 }} diff --git a/src/components/checkbox/demoSyncing/index.html b/src/components/checkbox/demoSyncing/index.html new file mode 100644 index 00000000000..f2e098c7848 --- /dev/null +++ b/src/components/checkbox/demoSyncing/index.html @@ -0,0 +1,30 @@ +
+

Using ngChecked:

+ +
+ +
+ Using <md-checkbox> + + {{ item }} selected + +
+ +
+ Using <input type="checkbox"> +
+ +
+
+ +
+ +
+ Two or more items are selected + Selected: {{ selected }} +
+ +
diff --git a/src/components/checkbox/demoSyncing/script.js b/src/components/checkbox/demoSyncing/script.js new file mode 100644 index 00000000000..ba7b2ecfcd3 --- /dev/null +++ b/src/components/checkbox/demoSyncing/script.js @@ -0,0 +1,18 @@ + +angular.module('checkboxDemo1', ['ngMaterial']) + +.controller('AppCtrl', function($scope) { + + $scope.items = [1,2,3,4,5]; + $scope.selected = []; + + $scope.toggle = function (item, list) { + var idx = list.indexOf(item); + if (idx > -1) list.splice(idx, 1); + else list.push(item); + }; + + $scope.exists = function (item, list) { + return list.indexOf(item) > -1; + }; +}); diff --git a/src/components/checkbox/demoSyncing/style.css b/src/components/checkbox/demoSyncing/style.css new file mode 100644 index 00000000000..3d083d9bd3a --- /dev/null +++ b/src/components/checkbox/demoSyncing/style.css @@ -0,0 +1,26 @@ +.checkboxDemo1 div { + clear: both; +} +.checkboxDemo1 md-checkbox { + float: left; +} + +legend { + color : #0000ba; +} + +p { + padding-left : 10px; +} + +.info { + padding-left:13px; +} + +div.standard { + padding:10px; padding-left:15px; +} + +fieldset.standard { + margin-left:10px; +}