mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
parent
e8f4305e9d
commit
d802ed1b36
2 changed files with 7 additions and 2 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}));
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue