import {MatSnackBarModule} from '@angular/material/snack-bar';
MatSnackBar
Service to dispatch Material Design snack bar messages.
dismiss | |
---|---|
Dismisses the currently-visible snack bar. |
open | |
---|---|
Opens a snackbar with a message and an optional action. | |
Parameters | |
message string | The message to show in the snackbar. |
action string = '' | The label for the snackbar action. |
config? MatSnackBarConfig | Additional configuration options for the snackbar. |
Returns | |
MatSnackBarRef<SimpleSnackBar> |
openFromComponent | |
---|---|
Creates and dispatches a snack bar with a custom component for the content, removing any currently opened snack bars. | |
Parameters | |
component ComponentType<T> | Component to be instantiated. |
config? MatSnackBarConfig | Extra configuration for the snack bar. |
Returns | |
MatSnackBarRef<T> |
openFromTemplate | |
---|---|
Creates and dispatches a snack bar with a custom template for the content, removing any currently opened snack bars. | |
Parameters | |
template TemplateRef<any> | Template to be instantiated. |
config? MatSnackBarConfig | Extra configuration for the snack bar. |
Returns | |
MatSnackBarRef<EmbeddedViewRef<any>> |
SimpleSnackBar
A component used to open as the default snack bar, matching material spec. This should only be used internally by the snack bar service.
Selector: simple-snack-bar
Name | Description |
---|---|
| Data that was injected into the snack bar. |
| If the action button should be shown. |
|
action | |
---|---|
Performs the action on the snack bar. |
MatSnackBarConfig
Configuration used when opening a snack-bar.
Name | Description |
---|---|
| Message to be announced by the LiveAnnouncer. When opening a snackbar without a custom component or template, the announcement message will default to the specified message. |
| Data being injected into the child component. |
| Text layout direction for the snack bar. |
| The length of time in milliseconds to wait before automatically dismissing the snack bar. |
| The horizontal position to place the snack bar. |
| Extra CSS classes to be added to the snack bar container. |
| The politeness level for the MatAriaLiveAnnouncer announcement. |
| The vertical position to place the snack bar. |
| The view container to place the overlay for the snack bar into. |
MatSnackBarRef
Reference to a snack bar dispatched from the snack bar service.
Name | Description |
---|---|
| The instance of the component making up the content of the snack bar. |
afterDismissed | |
---|---|
Gets an observable that is notified when the snack bar is finished closing. | |
Returns | |
Observable<MatSnackBarDismiss> |
afterOpened | |
---|---|
Gets an observable that is notified when the snack bar has opened and appeared. | |
Returns | |
Observable<void> |
dismiss | |
---|---|
Dismisses the snack bar. |
dismissWithAction | |
---|---|
Marks the snackbar action clicked. |
onAction | |
---|---|
Gets an observable that is notified when the snack bar action is called. | |
Returns | |
Observable<void> |
Deprecated closeWithAction | |
---|---|
Marks the snackbar action clicked. |
MatSnackBarDismiss
Event that is emitted when a snack bar is dismissed.
Name | Description |
---|---|
| Whether the snack bar was dismissed using the action button. |
MatSnackBarHorizontalPosition
Possible values for horizontalPosition on MatSnackBarConfig.
Type: 'start' | 'center' | 'end' | 'left' | 'right'
MatSnackBarVerticalPosition
Possible values for verticalPosition on MatSnackBarConfig.
Type: 'top' | 'bottom'