ngValueDirective = function() {
  return {
    restrict: 'A',
    priority: 100,
    compile: function(tpl, tplAttr) {
      if (CONSTANT_VALUE_REGEXP.test(tplAttr.ngValue)) {
        return function ngValueConstantLink(scope, elm, attr) {
          attr.$set('value', scope.$eval(attr.ngValue));
        };
      } else {
        return function ngValueLink(scope, elm, attr) {
          scope.$watch(attr.ngValue, function valueWatchAction(value) {
            attr.$set('value', value);
          });
        };
      }
    }
  };
}
@ngdoc directive
@name ngValue

@description
Binds the given expression to the value of `<option>` or {@link input[radio] `input[radio]`},
so that when the element is selected, the {@link ngModel `ngModel`} of that element is set to
the bound value.

`ngValue` is useful when dynamically generating lists of radio buttons using
{@link ngRepeat `ngRepeat`}, as shown below.

Likewise, `ngValue` can be used to generate `<option>` elements for
the {@link select `select`} element. In that case however, only strings are supported
for the `value `attribute, so the resulting `ngModel` will always be a string.
Support for `select` models with non-string values is available via `ngOptions`.

@element input
@param {string=} ngValue angular expression, whose value will be bound to the `value` attribute
  of the `input` element

@example
    <example name="ngValue-directive" module="valueExample">
      <file name="index.html">
       <script>
          angular.module('valueExample', [])
            .controller('ExampleController', ['$scope', function($scope) {
              $scope.names = ['pizza', 'unicorns', 'robots'];
              $scope.my = { favorite: 'unicorns' };
            }]);
       </script>
        <form ng-controller="ExampleController">
          <h2>Which is your favorite?</h2>
            <label ng-repeat="name in names" for="{{name}}">
              {{name}}
              <input type="radio"
                     ng-model="my.favorite"
                     ng-value="name"
                     id="{{name}}"
                     name="favorite">
            </label>
          <div>You chose {{my.favorite}}</div>
        </form>
      </file>
      <file name="protractor.js" type="protractor">
        var favorite = element(by.binding('my.favorite'));

        it('should initialize to model', function() {
          expect(favorite.getText()).toContain('unicorns');
        });
        it('should bind the values to the inputs', function() {
          element.all(by.model('my.favorite')).get(0).click();
          expect(favorite.getText()).toContain('pizza');
        });
      </file>
    </example>