Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($rootScope): broadcast $destroy event on $rootScope
Browse files Browse the repository at this point in the history
Fixes #5169
  • Loading branch information
jeffbcross authored and tbosch committed Dec 4, 2013
1 parent e8f4305 commit d802ed1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion test/ng/rootScopeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));


Expand Down

0 comments on commit d802ed1

Please sign in to comment.