feat(snack-bar): add dismiss method to MdSnackBar service (#3069)

Adds a `dismiss` method to the snack bar service, which dismisses the currently-open instance, mostly for convenience since the spec only allows one snack bar to open at a time.
This commit is contained in:
Kristiyan Kostadinov
2017-02-21 20:34:24 +01:00
committed by mmalerba
parent bd6feb382b
commit 83b5842641
2 changed files with 22 additions and 0 deletions
+13
View File
@@ -150,6 +150,19 @@ describe('MdSnackBar', () => {
});
}));
it('should be able to get dismissed through the service', async(() => {
snackBar.open(simpleMessage);
viewContainerFixture.detectChanges();
expect(overlayContainerElement.childElementCount).toBeGreaterThan(0);
snackBar.dismiss();
viewContainerFixture.detectChanges();
viewContainerFixture.whenStable().then(() => {
expect(overlayContainerElement.childElementCount).toBe(0);
});
}));
it('should clean itself up when the view container gets destroyed', async(() => {
snackBar.open(simpleMessage, null, { viewContainerRef: testViewContainerRef });
viewContainerFixture.detectChanges();
+9
View File
@@ -105,6 +105,15 @@ export class MdSnackBar {
return simpleSnackBarRef;
}
/**
* Dismisses the currently-visible snack bar.
*/
dismiss(): void {
if (this._openedSnackBarRef) {
this._openedSnackBarRef.dismiss();
}
}
/**
* Attaches the snack bar container component to the overlay.
*/