From ade6c452753145c84884d17027a7865bf4b34b0c Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Tue, 20 Mar 2012 13:05:42 -0700 Subject: [PATCH] feat(input.radio): Allow value attribute to be interpolated --- src/directive/input.js | 2 ++ test/directive/inputSpec.js | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/directive/input.js b/src/directive/input.js index adb8102caf8a..c9553e395424 100644 --- a/src/directive/input.js +++ b/src/directive/input.js @@ -560,6 +560,8 @@ function radioInputType(scope, element, attr, ctrl) { var value = attr.value; element[0].checked = isDefined(value) && (value == ctrl.$viewValue); }; + + attr.$observe('value', ctrl.$render); } function checkboxInputType(scope, element, attr, ctrl) { diff --git a/test/directive/inputSpec.js b/test/directive/inputSpec.js index 22c77f53aaae..0b848df154d2 100644 --- a/test/directive/inputSpec.js +++ b/test/directive/inputSpec.js @@ -720,18 +720,30 @@ describe('input', function() { }); - // TODO(vojta): change interpolate ? - xit('should allow {{expr}} as value', function() { + it('should allow {{expr}} as value', function() { scope.some = 11; compileInput( '' + ''); - browserTrigger(inputElm[0]); - expect(scope.value).toBe(true); + scope.$apply(function() { + scope.value = 'blue'; + scope.some = 'blue'; + scope.other = 'red'; + }); + + expect(inputElm[0].checked).toBe(true); + expect(inputElm[1].checked).toBe(false); browserTrigger(inputElm[1]); - expect(scope.value).toBe(false); + expect(scope.value).toBe('red'); + + scope.$apply(function() { + scope.other = 'non-red'; + }); + + expect(inputElm[0].checked).toBe(false); + expect(inputElm[1].checked).toBe(false); }); });