mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-28 15:28:15 +00:00
fix(ngValue): bind properly inside ng-repeat
This commit is contained in:
parent
2cb907a836
commit
95c5df5958
2 changed files with 20 additions and 3 deletions
|
|
@ -1181,9 +1181,8 @@ var ngValueDirective = [function() {
|
||||||
attr.$set('value', scope.$eval(attr.ngValue));
|
attr.$set('value', scope.$eval(attr.ngValue));
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
attr.$$observers.value = [];
|
return function(scope, elm, attr) {
|
||||||
|
attr.$$observers.value = [];
|
||||||
return function(scope) {
|
|
||||||
scope.$watch(attr.ngValue, function(value) {
|
scope.$watch(attr.ngValue, function(value) {
|
||||||
attr.$set('value', value, false);
|
attr.$set('value', value, false);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1115,5 +1115,23 @@ describe('input', function() {
|
||||||
browserTrigger(inputElm, 'click');
|
browserTrigger(inputElm, 'click');
|
||||||
expect(scope.selected).toBe(scope.value);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue