mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
mmalerba
parent
bd6feb382b
commit
83b5842641
@@ -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();
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user