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

Commit d802ed1

Browse files
jeffbcrosstbosch
authored andcommitted
fix($rootScope): broadcast $destroy event on $rootScope
Fixes #5169
1 parent e8f4305 commit d802ed1

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/ng/rootScope.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,12 @@ function $RootScopeProvider(){
670670
*/
671671
$destroy: function() {
672672
// we can't destroy the root scope or a scope that has been already destroyed
673-
if ($rootScope == this || this.$$destroyed) return;
673+
if (this.$$destroyed) return;
674674
var parent = this.$parent;
675675

676676
this.$broadcast('$destroy');
677677
this.$$destroyed = true;
678+
if (this === $rootScope) return;
678679

679680
if (parent.$$childHead == this) parent.$$childHead = this.$$nextSibling;
680681
if (parent.$$childTail == this) parent.$$childTail = this.$$prevSibling;

test/ng/rootScopeSpec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,14 @@ describe('Scope', function() {
599599
}));
600600

601601

602-
it('should ignore remove on root', inject(function($rootScope) {
602+
it('should broadcast $destroy on rootScope', inject(function($rootScope) {
603+
var spy = spyOn(angular, 'noop');
604+
$rootScope.$on('$destroy', angular.noop);
603605
$rootScope.$destroy();
604606
$rootScope.$digest();
605607
expect(log).toEqual('123');
608+
expect(spy).toHaveBeenCalled();
609+
expect($rootScope.$$destroyed).toBe(true);
606610
}));
607611

608612

0 commit comments

Comments
 (0)