Skip to content

Commit 7a667c7

Browse files
committed
fix(select): do not throw when removing the element (e.g. via ngIf)
Fixes angular#15466 Closes angular#15468
1 parent 752b1e6 commit 7a667c7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/ng/directive/select.js

+2
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ var SelectController =
182182
updateScheduled = true;
183183

184184
$scope.$$postDigest(function() {
185+
if ($scope.$$destroyed) return;
186+
185187
updateScheduled = false;
186188
self.ngModelCtrl.$setViewValue(self.readValue());
187189
if (renderAfter) self.ngModelCtrl.$render();

test/ng/directive/selectSpec.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('select', function() {
77
formElement = jqLite('<form name="form">' + html + '</form>');
88
element = formElement.find('select');
99
$compile(formElement)(scope);
10-
scope.$apply();
10+
scope.$digest();
1111
}
1212

1313
function compileRepeatedOptions() {
@@ -767,6 +767,20 @@ describe('select', function() {
767767
expect(element).toEqualSelect([unknownValue()], '1', '2', '3');
768768
}
769769
);
770+
771+
772+
it('should not throw when removing the element and all its children', function() {
773+
var template =
774+
'<select ng-model="mySelect" ng-if="visible">' +
775+
'<option value="">--- Select ---</option>' +
776+
'</select>';
777+
scope.visible = true;
778+
779+
compile(template);
780+
781+
// It should not throw when removing the element
782+
scope.$apply('visible = false');
783+
});
770784
});
771785

772786

0 commit comments

Comments
 (0)