Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8dd4f14

Browse files
Abdessamad Idrissicaitp
Abdessamad Idrissi
authored andcommitted
docs(input): document ngValue directive
Extend the example with ng-value showing how to deal with default checked radio boxes. Closes angular#5654
1 parent 7ba30fd commit 8dd4f14

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/ng/directive/input.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,28 +309,35 @@ var inputType = {
309309
* @param {string=} name Property name of the form under which the control is published.
310310
* @param {string=} ngChange Angular expression to be executed when input changes due to user
311311
* interaction with the input element.
312+
* @param {string} ngValue Angular expression which sets the value to which the expression should
313+
* be set when selected.
312314
*
313315
* @example
314316
<doc:example>
315317
<doc:source>
316318
<script>
317319
function Ctrl($scope) {
318320
$scope.color = 'blue';
321+
$scope.specialValue = {
322+
"id": "12345",
323+
"value": "green"
324+
};
319325
}
320326
</script>
321327
<form name="myForm" ng-controller="Ctrl">
322328
<input type="radio" ng-model="color" value="red"> Red <br/>
323-
<input type="radio" ng-model="color" value="green"> Green <br/>
329+
<input type="radio" ng-model="color" ng-value="specialValue"> Green <br/>
324330
<input type="radio" ng-model="color" value="blue"> Blue <br/>
325-
<tt>color = {{color}}</tt><br/>
331+
<tt>color = {{color | json}}</tt><br/>
326332
</form>
333+
Note that `ng-value="specialValue"` sets radio item's value to be the value of `$scope.specialValue`.
327334
</doc:source>
328335
<doc:scenario>
329336
it('should change state', function() {
330-
expect(binding('color')).toEqual('blue');
337+
expect(binding('color')).toEqual('"blue"');
331338
332339
input('color').select('red');
333-
expect(binding('color')).toEqual('red');
340+
expect(binding('color')).toEqual('"red"');
334341
});
335342
</doc:scenario>
336343
</doc:example>

0 commit comments

Comments
 (0)