mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
docs(input): document ngValue directive
Extend the example with ng-value showing how to deal with default checked radio boxes. Closes #5654
This commit is contained in:
parent
7ba30fd2e7
commit
8dd4f14a04
1 changed files with 11 additions and 4 deletions
|
|
@ -309,6 +309,8 @@ var inputType = {
|
|||
* @param {string=} name Property name of the form under which the control is published.
|
||||
* @param {string=} ngChange Angular expression to be executed when input changes due to user
|
||||
* interaction with the input element.
|
||||
* @param {string} ngValue Angular expression which sets the value to which the expression should
|
||||
* be set when selected.
|
||||
*
|
||||
* @example
|
||||
<doc:example>
|
||||
|
|
@ -316,21 +318,26 @@ var inputType = {
|
|||
<script>
|
||||
function Ctrl($scope) {
|
||||
$scope.color = 'blue';
|
||||
$scope.specialValue = {
|
||||
"id": "12345",
|
||||
"value": "green"
|
||||
};
|
||||
}
|
||||
</script>
|
||||
<form name="myForm" ng-controller="Ctrl">
|
||||
<input type="radio" ng-model="color" value="red"> Red <br/>
|
||||
<input type="radio" ng-model="color" value="green"> Green <br/>
|
||||
<input type="radio" ng-model="color" ng-value="specialValue"> Green <br/>
|
||||
<input type="radio" ng-model="color" value="blue"> Blue <br/>
|
||||
<tt>color = {{color}}</tt><br/>
|
||||
<tt>color = {{color | json}}</tt><br/>
|
||||
</form>
|
||||
Note that `ng-value="specialValue"` sets radio item's value to be the value of `$scope.specialValue`.
|
||||
</doc:source>
|
||||
<doc:scenario>
|
||||
it('should change state', function() {
|
||||
expect(binding('color')).toEqual('blue');
|
||||
expect(binding('color')).toEqual('"blue"');
|
||||
|
||||
input('color').select('red');
|
||||
expect(binding('color')).toEqual('red');
|
||||
expect(binding('color')).toEqual('"red"');
|
||||
});
|
||||
</doc:scenario>
|
||||
</doc:example>
|
||||
|
|
|
|||
Loading…
Reference in a new issue