fix($rootScope): broadcast $destroy event on $rootScope

Fixes #5169
This commit is contained in:
Jeff Cross 2013-12-04 14:33:58 -08:00 committed by Tobias Bosch
parent e8f4305e9d
commit d802ed1b36
2 changed files with 7 additions and 2 deletions

View file

@ -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;

View file

@ -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);
}));