diff options
| author | Vojta Jina | 2012-03-29 13:50:27 -0700 |
|---|---|---|
| committer | Vojta Jina | 2012-03-29 14:05:19 -0700 |
| commit | 95c5df5958f6d42d08846fa40c10cb279ce76ee9 (patch) | |
| tree | aef8880ea2cbc5225ee60e5bee687750cb9937b5 | |
| parent | 2cb907a8366e3273890f5ef6174b2e3970cd1720 (diff) | |
| download | angular.js-95c5df5958f6d42d08846fa40c10cb279ce76ee9.tar.bz2 | |
fix(ngValue): bind properly inside ng-repeat
| -rw-r--r-- | src/ng/directive/input.js | 5 | ||||
| -rw-r--r-- | test/ng/directive/inputSpec.js | 18 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 2f7a6a64..3d53f7ca 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1181,9 +1181,8 @@ var ngValueDirective = [function() { attr.$set('value', scope.$eval(attr.ngValue)); }; } else { - attr.$$observers.value = []; - - return function(scope) { + return function(scope, elm, attr) { + attr.$$observers.value = []; scope.$watch(attr.ngValue, function(value) { attr.$set('value', value, false); }); diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index e5f083b3..734cb34d 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -1115,5 +1115,23 @@ describe('input', function() { browserTrigger(inputElm, 'click'); expect(scope.selected).toBe(scope.value); }); + + + it('should work inside ng-repeat', function() { + compileInput( + '<input type="radio" ng-repeat="i in items" ng-model="$parent.selected" ng-value="i.id">'); + + scope.$apply(function() { + scope.items = [{id: 1}, {id: 2}]; + scope.selected = 1; + }); + + inputElm = formElm.find('input'); + expect(inputElm[0].checked).toBe(true); + expect(inputElm[1].checked).toBe(false); + + browserTrigger(inputElm.eq(1), 'click'); + expect(scope.selected).toBe(2); + }); }); }); |
