Skip to content

Commit

Permalink
fix($rootScope): broadcast $destroy event on $rootScope
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbcross authored and jamesdaily committed Jan 27, 2014
1 parent 5c028eb commit 24713c9
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 24713c9

Please sign in to comment.