File tree 2 files changed +20
-1
lines changed
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,7 @@ function $RootScopeProvider(){
134
134
this . $$nextSibling = this . $$prevSibling =
135
135
this . $$childHead = this . $$childTail = null ;
136
136
this [ 'this' ] = this . $root = this ;
137
+ this . $$destroyed = false ;
137
138
this . $$asyncQueue = [ ] ;
138
139
this . $$listeners = { } ;
139
140
}
@@ -467,10 +468,12 @@ function $RootScopeProvider(){
467
468
* perform any necessary cleanup.
468
469
*/
469
470
$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 ;
471
473
var parent = this . $parent ;
472
474
473
475
this . $broadcast ( '$destroy' ) ;
476
+ this . $$destroyed = true ;
474
477
475
478
if ( parent . $$childHead == this ) parent . $$childHead = this . $$nextSibling ;
476
479
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() {
407
407
first . $destroy ( ) ;
408
408
expect ( log ) . toEqual ( 'first; first-child' ) ;
409
409
} ) ) ;
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
+ } ) ) ;
410
426
} ) ;
411
427
412
428
You can’t perform that action at this time.
0 commit comments