@@ -332,6 +332,7 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
332
332
let backdropToDetach = this . _backdropElement ;
333
333
334
334
if ( backdropToDetach ) {
335
+ let timeoutId : number ;
335
336
let finishDetach = ( ) => {
336
337
// It may not be attached to anything in certain cases (e.g. unit tests).
337
338
if ( backdropToDetach && backdropToDetach . parentNode ) {
@@ -344,6 +345,8 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
344
345
if ( this . _backdropElement == backdropToDetach ) {
345
346
this . _backdropElement = null ;
346
347
}
348
+
349
+ clearTimeout ( timeoutId ) ;
347
350
} ;
348
351
349
352
backdropToDetach . classList . remove ( 'cdk-overlay-backdrop-showing' ) ;
@@ -352,7 +355,9 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
352
355
this . _toggleClasses ( backdropToDetach , this . _config . backdropClass , false ) ;
353
356
}
354
357
355
- backdropToDetach . addEventListener ( 'transitionend' , finishDetach ) ;
358
+ this . _ngZone . runOutsideAngular ( ( ) => {
359
+ backdropToDetach ! . addEventListener ( 'transitionend' , finishDetach ) ;
360
+ } ) ;
356
361
357
362
// If the backdrop doesn't have a transition, the `transitionend` event won't fire.
358
363
// In this case we make it unclickable and we try to remove it after a delay.
@@ -361,7 +366,7 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
361
366
// Run this outside the Angular zone because there's nothing that Angular cares about.
362
367
// If it were to run inside the Angular zone, every test that used Overlay would have to be
363
368
// either async or fakeAsync.
364
- this . _ngZone . runOutsideAngular ( ( ) => setTimeout ( finishDetach , 500 ) ) ;
369
+ timeoutId = this . _ngZone . runOutsideAngular ( ( ) => setTimeout ( finishDetach , 500 ) ) ;
365
370
}
366
371
}
367
372
0 commit comments