Skip to content

Commit 161f319

Browse files
crisbetokara
authored andcommitted
fix(snack-bar): prevent error when opening multiple snack bars in fast succession (#2392)
Fixes #2390.
1 parent 61db84d commit 161f319

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/lib/snack-bar/snack-bar-container.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
9292
/** Handle end of animations, updating the state of the snackbar. */
9393
onAnimationEnd(event: AnimationTransitionEvent) {
9494
if (event.toState === 'void' || event.toState === 'complete') {
95-
this._ngZone.run(() => {
96-
this.onExit.next();
97-
this.onExit.complete();
98-
});
95+
this._completeExit();
9996
}
97+
10098
if (event.toState === 'visible') {
10199
this._ngZone.run(() => {
102100
this.onEnter.next();
@@ -131,8 +129,14 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
131129
* Makes sure the exit callbacks have been invoked when the element is destroyed.
132130
*/
133131
ngOnDestroy() {
134-
// Wait for the zone to settle before removing the element. Helps prevent
135-
// errors where we end up removing an element which is in the middle of an animation.
132+
this._completeExit();
133+
}
134+
135+
/**
136+
* Waits for the zone to settle before removing the element. Helps prevent
137+
* errors where we end up removing an element which is in the middle of an animation.
138+
*/
139+
private _completeExit() {
136140
this._ngZone.onMicrotaskEmpty.first().subscribe(() => {
137141
this.onExit.next();
138142
this.onExit.complete();

0 commit comments

Comments
 (0)