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

Commit

Permalink
fix(input): corrected NPE when input goes away
Browse files Browse the repository at this point in the history
Closes #392
  • Loading branch information
mhevery committed Jan 9, 2014
1 parent 06ab9e7 commit e97b9d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/directive/input_select.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class InputSelectDirective implements NgAttachAware {
}

/**
* This method invalidates the current state of the selector and forces a rerendering of the
* This method invalidates the current state of the selector and forces a re-rendering of the
* options using the [Scope.$evalAsync].
*/
dirty() {
Expand Down Expand Up @@ -175,7 +175,13 @@ class _SingleSelectMode extends _SelectMode {
var found = false;
_forEachOption((option, i) {
if (option == _unknownOption) return;
var selected = value == null ? option == _nullOption : expando[option].ngValue == value;
var selected;
if (value == null) {
selected = option == _nullOption;
} else {
OptionValueDirective optionValueDirective = expando[option];
selected = optionValueDirective == null ? false : optionValueDirective.ngValue == value;
}
found = found || selected;
option.selected = selected;
});
Expand Down
22 changes: 22 additions & 0 deletions test/directive/input_select_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,28 @@ main() {
});
});
});

it('issue #392', () {
_.compile(
'<div>' +
'<div ng-if="attached">' +
'<select ng-model="model">' +
'<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 e97b9d0

Please sign in to comment.