File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -219,6 +219,23 @@ describe('MdSnackBar', () => {
219219 } ) ;
220220 } ) ;
221221 } ) ) ;
222+
223+ it ( 'should remove past snackbars when opening new snackbars' , async ( ( ) => {
224+ snackBar . open ( 'First snackbar' ) ;
225+ viewContainerFixture . detectChanges ( ) ;
226+
227+ snackBar . open ( 'Second snackbar' ) ;
228+ viewContainerFixture . detectChanges ( ) ;
229+
230+ viewContainerFixture . whenStable ( ) . then ( ( ) => {
231+ snackBar . open ( 'Third snackbar' ) ;
232+ viewContainerFixture . detectChanges ( ) ;
233+
234+ viewContainerFixture . whenStable ( ) . then ( ( ) => {
235+ expect ( overlayContainerElement . textContent . trim ( ) ) . toBe ( 'Third snackbar' ) ;
236+ } ) ;
237+ } ) ;
238+ } ) ) ;
222239} ) ;
223240
224241@Directive ( { selector : 'dir-with-view-container' } )
Original file line number Diff line number Diff line change @@ -48,7 +48,10 @@ export class MdSnackBar {
4848
4949 // When the snackbar is dismissed, clear the reference to it.
5050 snackBarRef . afterDismissed ( ) . subscribe ( ( ) => {
51- this . _snackBarRef = null ;
51+ // Clear the snackbar ref if it hasn't already been replaced by a newer snackbar.
52+ if ( this . _snackBarRef == snackBarRef ) {
53+ this . _snackBarRef = null ;
54+ }
5255 } ) ;
5356
5457 // If a snack bar is already in view, dismiss it and enter the new snack bar after exit
You can’t perform that action at this time.
0 commit comments