mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(snack-bar): prevent error when opening multiple snack bars in fast succession (#2392)
Fixes #2390.
This commit is contained in:
committed by
Kara
parent
61db84d150
commit
161f319d17
@@ -92,11 +92,9 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
|
||||
/** Handle end of animations, updating the state of the snackbar. */
|
||||
onAnimationEnd(event: AnimationTransitionEvent) {
|
||||
if (event.toState === 'void' || event.toState === 'complete') {
|
||||
this._ngZone.run(() => {
|
||||
this.onExit.next();
|
||||
this.onExit.complete();
|
||||
});
|
||||
this._completeExit();
|
||||
}
|
||||
|
||||
if (event.toState === 'visible') {
|
||||
this._ngZone.run(() => {
|
||||
this.onEnter.next();
|
||||
@@ -131,8 +129,14 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
|
||||
* Makes sure the exit callbacks have been invoked when the element is destroyed.
|
||||
*/
|
||||
ngOnDestroy() {
|
||||
// Wait for the zone to settle before removing the element. Helps prevent
|
||||
// errors where we end up removing an element which is in the middle of an animation.
|
||||
this._completeExit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the zone to settle before removing the element. Helps prevent
|
||||
* errors where we end up removing an element which is in the middle of an animation.
|
||||
*/
|
||||
private _completeExit() {
|
||||
this._ngZone.onMicrotaskEmpty.first().subscribe(() => {
|
||||
this.onExit.next();
|
||||
this.onExit.complete();
|
||||
|
||||
Reference in New Issue
Block a user