diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 77cba19968ab..3d1d67f75675 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -196,6 +196,7 @@ function $RootScopeProvider(){ // ensure that there is just one async queue per $rootScope and its children child.$$asyncQueue = this.$$asyncQueue; child.$$postDigestQueue = this.$$postDigestQueue; + child.$on('$destroy', function() { child.$$destroyed = true; }); } else { // Only create a child scope class if somebody asks for one, // but cache it to allow the VM to optimize lookups. diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index e3168ec10e86..c21500b31902 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -994,6 +994,13 @@ describe('Scope', function() { expect(log).toBe('123'); })); + it('should broadcast the $destroy only once', inject(function($rootScope, log) { + var isolateScope = first.$new(true); + isolateScope.$on('$destroy', log.fn('event')); + first.$destroy(); + isolateScope.$destroy(); + expect(log).toEqual('event'); + })); it('should decrement ancestor $$listenerCount entries', inject(function($rootScope) { var EVENT = 'fooEvent',