fix(ngValue): bind properly inside ng-repeat

This commit is contained in:
Vojta Jina 2012-03-29 13:50:27 -07:00
parent 2cb907a836
commit 95c5df5958
2 changed files with 20 additions and 3 deletions

View file

@ -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);
});

View file

@ -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);
});
});
});