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

Commit e13224b

Browse files
mhoffmeyerDCpetebacondarwin
authored andcommitted
docs(input[checkbox]): update example to use ngModel best practices
It's not required for the example to function, but it prevents scope weirdness/unexpected behavior when using directives (especially with ngTransclude!). I think it's a good pattern to encourage and might prevent a bug down the road for for people who just scan for the monospace font. See [Understanding Scopes](https://github.com/angular/angular.js/wiki/Understanding-Scopes) for mgModel best practices. Closes #10851
1 parent 36a14e6 commit e13224b

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/ng/directive/input.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -902,28 +902,30 @@ var inputType = {
902902
<script>
903903
angular.module('checkboxExample', [])
904904
.controller('ExampleController', ['$scope', function($scope) {
905-
$scope.value1 = true;
906-
$scope.value2 = 'YES'
905+
$scope.checkboxModel = {
906+
value1 : true,
907+
value2 : 'YES'
908+
};
907909
}]);
908910
</script>
909911
<form name="myForm" ng-controller="ExampleController">
910-
Value1: <input type="checkbox" ng-model="value1"> <br/>
911-
Value2: <input type="checkbox" ng-model="value2"
912+
Value1: <input type="checkbox" ng-model="checkboxModel.value1"> <br/>
913+
Value2: <input type="checkbox" ng-model="checkboxModel.value2"
912914
ng-true-value="'YES'" ng-false-value="'NO'"> <br/>
913-
<tt>value1 = {{value1}}</tt><br/>
914-
<tt>value2 = {{value2}}</tt><br/>
915+
<tt>value1 = {{checkboxModel.value1}}</tt><br/>
916+
<tt>value2 = {{checkboxModel.value2}}</tt><br/>
915917
</form>
916918
</file>
917919
<file name="protractor.js" type="protractor">
918920
it('should change state', function() {
919-
var value1 = element(by.binding('value1'));
920-
var value2 = element(by.binding('value2'));
921+
var value1 = element(by.binding('checkboxModel.value1'));
922+
var value2 = element(by.binding('checkboxModel.value2'));
921923
922924
expect(value1.getText()).toContain('true');
923925
expect(value2.getText()).toContain('YES');
924926
925-
element(by.model('value1')).click();
926-
element(by.model('value2')).click();
927+
element(by.model('checkboxModel.value1')).click();
928+
element(by.model('checkboxModel.value2')).click();
927929
928930
expect(value1.getText()).toContain('false');
929931
expect(value2.getText()).toContain('NO');

0 commit comments

Comments
 (0)