This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,7 @@ function $RootScopeProvider(){
134134 this . $$nextSibling = this . $$prevSibling =
135135 this . $$childHead = this . $$childTail = null ;
136136 this [ 'this' ] = this . $root = this ;
137+ this . $$destroyed = false ;
137138 this . $$asyncQueue = [ ] ;
138139 this . $$listeners = { } ;
139140 }
@@ -467,10 +468,12 @@ function $RootScopeProvider(){
467468 * perform any necessary cleanup.
468469 */
469470 $destroy : function ( ) {
470- if ( $rootScope == this ) return ; // we can't remove the root node;
471+ // we can't destroy the root scope or a scope that has been already destroyed
472+ if ( $rootScope == this || this . $$destroyed ) return ;
471473 var parent = this . $parent ;
472474
473475 this . $broadcast ( '$destroy' ) ;
476+ this . $$destroyed = true ;
474477
475478 if ( parent . $$childHead == this ) parent . $$childHead = this . $$nextSibling ;
476479 if ( parent . $$childTail == this ) parent . $$childTail = this . $$prevSibling ;
Original file line number Diff line number Diff line change @@ -407,6 +407,22 @@ describe('Scope', function() {
407407 first . $destroy ( ) ;
408408 expect ( log ) . toEqual ( 'first; first-child' ) ;
409409 } ) ) ;
410+
411+
412+ it ( 'should $destroy a scope only once and ignore any further destroy calls' ,
413+ inject ( function ( $rootScope ) {
414+ $rootScope . $digest ( ) ;
415+ expect ( log ) . toBe ( '123' ) ;
416+
417+ first . $destroy ( ) ;
418+ first . $apply ( ) ;
419+ expect ( log ) . toBe ( '12323' ) ;
420+
421+ first . $destroy ( ) ;
422+ first . $destroy ( ) ;
423+ first . $apply ( ) ;
424+ expect ( log ) . toBe ( '1232323' ) ;
425+ } ) ) ;
410426 } ) ;
411427
412428
You can’t perform that action at this time.
0 commit comments