Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(select): do not break when removing the element (e.g. via ngIf) #15468

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ng/directive/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ var SelectController =
updateScheduled = true;

$scope.$$postDigest(function() {
if ($scope.$$destroyed) return;

updateScheduled = false;
self.ngModelCtrl.$setViewValue(self.readValue());
if (renderAfter) self.ngModelCtrl.$render();
Expand Down
16 changes: 15 additions & 1 deletion test/ng/directive/selectSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('select', function() {
formElement = jqLite('<form name="form">' + html + '</form>');
element = formElement.find('select');
$compile(formElement)(scope);
scope.$apply();
scope.$digest();
}

function compileRepeatedOptions() {
Expand Down Expand Up @@ -767,6 +767,20 @@ describe('select', function() {
expect(element).toEqualSelect([unknownValue()], '1', '2', '3');
}
);


it('should not throw when removing the element and all its children', function() {
var template =
'<select ng-model="mySelect" ng-if="visible">' +
'<option value="">--- Select ---</option>' +
'</select>';
scope.visible = true;

compile(template);

// It should not throw when removing the element
scope.$apply('visible = false');
});
});


Expand Down