From d802ed1b3680cfc1751777fac465b92ee29944dc Mon Sep 17 00:00:00 2001 From: Jeff Cross Date: Wed, 4 Dec 2013 14:33:58 -0800 Subject: [PATCH] fix($rootScope): broadcast $destroy event on $rootScope Fixes #5169 --- src/ng/rootScope.js | 3 ++- test/ng/rootScopeSpec.js | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 13ee4c70a0b1..a54fdc98fc1e 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -670,11 +670,12 @@ function $RootScopeProvider(){ */ $destroy: function() { // we can't destroy the root scope or a scope that has been already destroyed - if ($rootScope == this || this.$$destroyed) return; + if (this.$$destroyed) return; var parent = this.$parent; this.$broadcast('$destroy'); this.$$destroyed = true; + if (this === $rootScope) return; if (parent.$$childHead == this) parent.$$childHead = this.$$nextSibling; if (parent.$$childTail == this) parent.$$childTail = this.$$prevSibling; diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index 69447a3c20b9..287b535634da 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -599,10 +599,14 @@ describe('Scope', function() { })); - it('should ignore remove on root', inject(function($rootScope) { + it('should broadcast $destroy on rootScope', inject(function($rootScope) { + var spy = spyOn(angular, 'noop'); + $rootScope.$on('$destroy', angular.noop); $rootScope.$destroy(); $rootScope.$digest(); expect(log).toEqual('123'); + expect(spy).toHaveBeenCalled(); + expect($rootScope.$$destroyed).toBe(true); }));