@@ -416,7 +416,7 @@ function MdToastProvider($$interimElementProvider) {
416416 }
417417
418418 /* @ngInject */
419- function toastDefaultOptions ( $animate , $mdToast , $mdUtil , $mdMedia , $document ) {
419+ function toastDefaultOptions ( $animate , $mdToast , $mdUtil , $mdMedia , $document , $q ) {
420420 var SWIPE_EVENTS = '$md.swipeleft $md.swiperight $md.swipeup $md.swipedown' ;
421421 return {
422422 onShow : onShow ,
@@ -518,6 +518,12 @@ function MdToastProvider($$interimElementProvider) {
518518 } ) ;
519519 }
520520
521+ /**
522+ * @param {object } scope the toast's scope
523+ * @param {JQLite } element the toast to be removed
524+ * @param {object } options
525+ * @return {Promise<*> } a Promise to remove the element immediately or to animate it out.
526+ */
521527 function onRemove ( scope , element , options ) {
522528 if ( scope . toast && scope . toast . actionKey ) {
523529 removeActionKeyListener ( ) ;
@@ -526,7 +532,8 @@ function MdToastProvider($$interimElementProvider) {
526532 if ( options . parent ) options . parent . addClass ( 'md-toast-animating' ) ;
527533 if ( options . openClass ) options . parent . removeClass ( options . openClass ) ;
528534
529- return ( ( options . $destroy === true ) ? element . remove ( ) : $animate . leave ( element ) )
535+ // Don't run the leave animation if the element has already been destroyed.
536+ return ( ( options . $destroy === true ) ? $q . when ( element . remove ( ) ) : $animate . leave ( element ) )
530537 . then ( function ( ) {
531538 if ( options . parent ) options . parent . removeClass ( 'md-toast-animating' ) ;
532539 if ( $mdUtil . hasComputedStyle ( options . parent , 'position' , 'static' ) ) {
0 commit comments