From 26cd0e45ffb219619ad8503a8134cb24c8221130 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 9 Aug 2016 16:02:52 -0500 Subject: [PATCH] Don't run $apply if the scope was destroyed This can happen when the "stream" that triggers safeApply was completed after the scope was destroyed (e.g. the angular app was destroyed, which happens during jasmine unit tests) Maybe we could also put a $destroy event listener to stop this observable as soon as it happens. --- src/safeApply.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/safeApply.js b/src/safeApply.js index c61ceba..a3b3628 100644 --- a/src/safeApply.js +++ b/src/safeApply.js @@ -21,7 +21,7 @@ $scope.$apply(function () { onError(error); }); }, function (){ - ($scope.$$phase || $scope.$root.$$phase) ? + ($scope.$$destroyed || $scope.$$phase || $scope.$root.$$phase) ? onComplete() : $scope.$apply(function () { onComplete(); }); });