Skip to content

Commit

Permalink
fix(directive): ng:options incorrectly re-grew options on datasource …
Browse files Browse the repository at this point in the history
…change

Closes angular#464
  • Loading branch information
mhevery committed Jul 20, 2011
1 parent c32184d commit 48452da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

### Bug Fixes
- Issue #449: [ng:options] should support binding to a property of an item.
- Issue #464: [ng:options] incorrectly re-grew options on datasource change



Expand Down
5 changes: 4 additions & 1 deletion src/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,13 @@ angularWidget('select', function(element){
}
}
}
if (fragment) select.append(jqLite(fragment));
if (fragment) {
select.append(jqLite(fragment));
}
// shrink children
while(optionElements.length > index) {
optionElements.pop().remove();
optionTexts.pop();
delete lastSelectValue[optionElements.length];
}

Expand Down
18 changes: 18 additions & 0 deletions test/widgetsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,24 @@ describe("widget", function(){
expect(select.find('option').length).toEqual(1); // we add back the special empty option
});

it('should shrink and then grow list', function(){
createSingleSelect();
scope.values = [{name:'A'}, {name:'B'}, {name:'C'}];
scope.selected = scope.values[0];
scope.$eval();
expect(select.find('option').length).toEqual(3);

scope.values = [{name:'1'}, {name:'2'}];
scope.selected = scope.values[0];
scope.$eval();
expect(select.find('option').length).toEqual(2);

scope.values = [{name:'A'}, {name:'B'}, {name:'C'}];
scope.selected = scope.values[0];
scope.$eval();
expect(select.find('option').length).toEqual(3);
});

it('should update list', function(){
createSingleSelect();
scope.values = [{name:'A'}, {name:'B'}, {name:'C'}];
Expand Down

0 comments on commit 48452da

Please sign in to comment.