Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(select): Corrected NPE if select multiple nested in ng-if
Browse files Browse the repository at this point in the history
Closes #428
  • Loading branch information
mhevery committed Feb 5, 2014
1 parent 7fa38fd commit 6228692
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/directive/input_select.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,14 @@ class _MultipleSelectionMode extends _SelectMode {
Function fn = (o, i) => o.selected = null;

if (selectedValues is List) {
fn = (o, i) => o.selected = selectedValues.contains(expando[o].ngValue);
fn = (o, i) {
var selected = expando[o];
if (selected == null) {
return false;
} else {
return o.selected = selectedValues.contains(selected.ngValue);
}
};
}

_forEachOption(fn);
Expand Down
23 changes: 23 additions & 0 deletions test/directive/input_select_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,29 @@ main() {
_.rootScope.$apply();
expect(_.rootElement).toEqualSelect([['a'], 'b']);
});


it('issue #428', () {
_.compile(
'<div>' +
'<div ng-if="attached">' +
'<select ng-model="model" multiple>' +
'<option value="a">foo</option>' +
'<option value="b">bar</option>' +
'</select>' +
'</div>' +
'</div>');
_.rootScope.model = ['a'];
_.rootScope.attached = true;
_.rootScope.$apply();
expect(_.rootElement).toEqualSelect([['a'], 'b']);
_.rootScope.attached = false;
_.rootScope.$apply();
expect(_.rootElement).toEqualSelect([]);
_.rootScope.attached = true;
_.rootScope.$apply();
expect(_.rootElement).toEqualSelect([['a'], 'b']);
});
});


Expand Down

0 comments on commit 6228692

Please sign in to comment.