diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index 20271e2077aa..55381ff72835 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -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(); diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index 51b093728fd6..6990cfeb9eb9 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -7,7 +7,7 @@ describe('select', function() { formElement = jqLite('
' + html + '
'); element = formElement.find('select'); $compile(formElement)(scope); - scope.$apply(); + scope.$digest(); } function compileRepeatedOptions() { @@ -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 = + ''; + scope.visible = true; + + compile(template); + + // It should not throw when removing the element + scope.$apply('visible = false'); + }); });