@@ -332,6 +332,7 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
332332 let backdropToDetach = this . _backdropElement ;
333333
334334 if ( backdropToDetach ) {
335+ let timeoutId : number ;
335336 let finishDetach = ( ) => {
336337 // It may not be attached to anything in certain cases (e.g. unit tests).
337338 if ( backdropToDetach && backdropToDetach . parentNode ) {
@@ -344,6 +345,8 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
344345 if ( this . _backdropElement == backdropToDetach ) {
345346 this . _backdropElement = null ;
346347 }
348+
349+ clearTimeout ( timeoutId ) ;
347350 } ;
348351
349352 backdropToDetach . classList . remove ( 'cdk-overlay-backdrop-showing' ) ;
@@ -352,7 +355,9 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
352355 this . _toggleClasses ( backdropToDetach , this . _config . backdropClass , false ) ;
353356 }
354357
355- backdropToDetach . addEventListener ( 'transitionend' , finishDetach ) ;
358+ this . _ngZone . runOutsideAngular ( ( ) => {
359+ backdropToDetach ! . addEventListener ( 'transitionend' , finishDetach ) ;
360+ } ) ;
356361
357362 // If the backdrop doesn't have a transition, the `transitionend` event won't fire.
358363 // 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 {
361366 // Run this outside the Angular zone because there's nothing that Angular cares about.
362367 // If it were to run inside the Angular zone, every test that used Overlay would have to be
363368 // either async or fakeAsync.
364- this . _ngZone . runOutsideAngular ( ( ) => setTimeout ( finishDetach , 500 ) ) ;
369+ timeoutId = this . _ngZone . runOutsideAngular ( ( ) => setTimeout ( finishDetach , 500 ) ) ;
365370 }
366371 }
367372
0 commit comments