@@ -1367,17 +1367,66 @@ var ngListDirective = function() {
1367
1367
1368
1368
1369
1369
var CONSTANT_VALUE_REGEXP = / ^ ( t r u e | f a l s e | \d + ) $ / ;
1370
-
1370
+ /**
1371
+ * @ngdoc directive
1372
+ * @name ng.directive:ngValue
1373
+ *
1374
+ * @description
1375
+ * Binds the given expression to the value of `input[select]` or `input[radio]`, so
1376
+ * that when the element is selected, the `ngModel` of that element is set to the
1377
+ * bound value.
1378
+ *
1379
+ * `ngValue` is useful when dynamically generating lists of radio buttons using `ng-repeat`, as
1380
+ * shown below.
1381
+ *
1382
+ * @element input
1383
+ * @param {string= } ngValue angular expression, whose value will be bound to the `value` attribute
1384
+ * of the `input` element
1385
+ *
1386
+ * @example
1387
+ <doc:example>
1388
+ <doc:source>
1389
+ <script>
1390
+ function Ctrl($scope) {
1391
+ $scope.names = ['pizza', 'unicorns', 'robots'];
1392
+ $scope.my = { favorite: 'unicorns' };
1393
+ }
1394
+ </script>
1395
+ <form ng-controller="Ctrl">
1396
+ <h2>Which is your favorite?</h2>
1397
+ <label ng-repeat="name in names" for="{{name}}">
1398
+ {{name}}
1399
+ <input type="radio"
1400
+ ng-model="my.favorite"
1401
+ ng-value="name"
1402
+ id="{{name}}"
1403
+ name="favorite">
1404
+ </label>
1405
+ </span>
1406
+ <div>You chose {{my.favorite}}</div>
1407
+ </form>
1408
+ </doc:source>
1409
+ <doc:scenario>
1410
+ it('should initialize to model', function() {
1411
+ expect(binding('my.favorite')).toEqual('unicorns');
1412
+ });
1413
+ it('should bind the values to the inputs', function() {
1414
+ input('my.favorite').select('pizza');
1415
+ expect(binding('my.favorite')).toEqual('pizza');
1416
+ });
1417
+ </doc:scenario>
1418
+ </doc:example>
1419
+ */
1371
1420
var ngValueDirective = function ( ) {
1372
1421
return {
1373
1422
priority : 100 ,
1374
1423
compile : function ( tpl , tplAttr ) {
1375
1424
if ( CONSTANT_VALUE_REGEXP . test ( tplAttr . ngValue ) ) {
1376
- return function ( scope , elm , attr ) {
1425
+ return function ngValueConstantLink ( scope , elm , attr ) {
1377
1426
attr . $set ( 'value' , scope . $eval ( attr . ngValue ) ) ;
1378
1427
} ;
1379
1428
} else {
1380
- return function ( scope , elm , attr ) {
1429
+ return function ngValueLink ( scope , elm , attr ) {
1381
1430
scope . $watch ( attr . ngValue , function valueWatchAction ( value ) {
1382
1431
attr . $set ( 'value' , value ) ;
1383
1432
} ) ;
0 commit comments