mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-17 19:11:08 +00:00
parent
e8f4305e9d
commit
d802ed1b36
2 changed files with 7 additions and 2 deletions
|
|
@ -670,11 +670,12 @@ function $RootScopeProvider(){
|
||||||
*/
|
*/
|
||||||
$destroy: function() {
|
$destroy: function() {
|
||||||
// we can't destroy the root scope or a scope that has been already destroyed
|
// 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;
|
var parent = this.$parent;
|
||||||
|
|
||||||
this.$broadcast('$destroy');
|
this.$broadcast('$destroy');
|
||||||
this.$$destroyed = true;
|
this.$$destroyed = true;
|
||||||
|
if (this === $rootScope) return;
|
||||||
|
|
||||||
if (parent.$$childHead == this) parent.$$childHead = this.$$nextSibling;
|
if (parent.$$childHead == this) parent.$$childHead = this.$$nextSibling;
|
||||||
if (parent.$$childTail == this) parent.$$childTail = this.$$prevSibling;
|
if (parent.$$childTail == this) parent.$$childTail = this.$$prevSibling;
|
||||||
|
|
|
||||||
|
|
@ -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.$destroy();
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
expect(log).toEqual('123');
|
expect(log).toEqual('123');
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
expect($rootScope.$$destroyed).toBe(true);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue