ngx-snackbar
Angular 7 component for Snackbar (AKA Toast) notifications.
Installation
npm install --save ngx-snackbar
Usage
Import default styles
Import styles.css into your app. This step is optional, feel free to theme the snackbars to your liking.
index.html
Angular CLI
.angular-cli.json
... "styles": ,...
SnackbarModule
Import ;;;; @ {}
SystemJS
System;
ngx-snackbar
tag on your template
Place the
Options
Use these properties to customize the snackbar component.
Name | Description | Type | Default | Optional |
---|---|---|---|---|
position | The position where the snackbar appears | top-left , top-center , top-right , bottom-left , bottom-center , bottom-right |
bottom-right |
true |
max | The maximum number of snackbars allowed on screen | number | (Infinite) | true |
timeout | Number of milliseconds before the snackbar closes | number | (Infinite) | true |
color | Text color in hex | string | auto |
true |
background | Background color in hex | string | #343434 |
true |
customClass | Custom class to append to the snackbar | string | true | |
accent | Action button color. Requires action.text |
string | #2196f3 |
true |
Events
Name | Description | Return |
---|---|---|
onAdd | Callback gets triggered on snackbar add | Object |
onRemove | Callback gets triggered on snackbar remove | Object |
onClear | Callback gets triggered on snackbar clear | boolean |
add
method options plus id
string.
Object: SnackbarService
to control snackbars
Use the Import SnakckbarService
from ngx-snackbar
:
;;
Methods
add(options: Object)
All options will override global values set on ngx-snackbar
.
Name | Description | Type | Default | Optional |
---|---|---|---|---|
msg | Message to display in the snackbar (HTML accepted) | string | false | |
timeout | Number of milliseconds before the snackbar closes | number | (Infinite) | true |
color | Text color in hex | string | auto |
true |
background | Background color in hex | string | #343434 |
true |
customClass | Custom class to append to the snackbar | string | true | |
action.text | Action button text. Snackbar will automatically dismiss on click | string | true | |
action.color | Action button color. Requires action.text |
string | #2196f3 |
true |
action.onClick | Action button callback. Requires action.text |
Function | true | |
onAdd | Callback gets triggered on snackbar add | Function | true | |
onRemove | Callback gets triggered on snackbar remove | Function | true |
remove(id: string)
Remove snackbar on screen by ID.
clear()
Clears all snackbars on screen.
Example
;;
Credits
Thanks angular-library-starter for the compilation scripts.