From 7692065ee3b7d9f6985c197e367d1de04f24f115 Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Thu, 3 Oct 2013 13:28:44 -0700 Subject: [PATCH] docs(ngValue): add docs for ngValue directive --- src/ng/directive/input.js | 55 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index fa953419c02c..76e7f72b4347 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -958,7 +958,7 @@ var VALID_CLASS = 'ng-valid', * * - * + * */ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$parse', function($scope, $exceptionHandler, $attr, $element, $parse) { @@ -1366,17 +1366,64 @@ var ngListDirective = function() { var CONSTANT_VALUE_REGEXP = /^(true|false|\d+)$/; - +/** + * @ngdoc directive + * @name ng.directive:ngValue + * + * @description + * Binds the given expression to the value of `input[select]` or `input[radio]`, so + * that when the element is selected, the `ngModel` of that element is set to the + * bound value. + * + * `ngValue` is useful for repeating over input elements, as shown below. + * + * @element input + * @param {string=} ngValue angular expression to bind the value of the input to. + * + * @example + + + +
+

Which is your favorite?

+ + +
You chose {{my.favorite}}
+
+
+ + it('should initialize to model', function() { + expect(binding('my.favorite')).toEqual('unicorns'); + }); + it('should bind the values to the inputs', function() { + input('my.favorite').select('pizza'); + expect(binding('my.favorite')).toEqual('pizza'); + }); + +
+ */ var ngValueDirective = function() { return { priority: 100, compile: function(tpl, tplAttr) { if (CONSTANT_VALUE_REGEXP.test(tplAttr.ngValue)) { - return function(scope, elm, attr) { + return function ngValueConstantLink(scope, elm, attr) { attr.$set('value', scope.$eval(attr.ngValue)); }; } else { - return function(scope, elm, attr) { + return function ngValueLink(scope, elm, attr) { scope.$watch(attr.ngValue, function valueWatchAction(value) { attr.$set('value', value); });