@@ -416,7 +416,7 @@ function MdToastProvider($$interimElementProvider) {
416
416
}
417
417
418
418
/* @ngInject */
419
- function toastDefaultOptions ( $animate , $mdToast , $mdUtil , $mdMedia , $document ) {
419
+ function toastDefaultOptions ( $animate , $mdToast , $mdUtil , $mdMedia , $document , $q ) {
420
420
var SWIPE_EVENTS = '$md.swipeleft $md.swiperight $md.swipeup $md.swipedown' ;
421
421
return {
422
422
onShow : onShow ,
@@ -518,6 +518,12 @@ function MdToastProvider($$interimElementProvider) {
518
518
} ) ;
519
519
}
520
520
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
+ */
521
527
function onRemove ( scope , element , options ) {
522
528
if ( scope . toast && scope . toast . actionKey ) {
523
529
removeActionKeyListener ( ) ;
@@ -526,7 +532,8 @@ function MdToastProvider($$interimElementProvider) {
526
532
if ( options . parent ) options . parent . addClass ( 'md-toast-animating' ) ;
527
533
if ( options . openClass ) options . parent . removeClass ( options . openClass ) ;
528
534
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 ) )
530
537
. then ( function ( ) {
531
538
if ( options . parent ) options . parent . removeClass ( 'md-toast-animating' ) ;
532
539
if ( $mdUtil . hasComputedStyle ( options . parent , 'position' , 'static' ) ) {
0 commit comments