Toast Overlay
You can use the ToasterService
in @abp/ng.theme.shared package to display messages in an overlay by placing at the root level in your project.
Getting Started
You do not have to provide the ToasterService
at module or component level, because it is already provided in root. You can inject and start using it immediately in your components, directives, or services.
Usage
You can use the success
, warn
, error
, and info
methods of ToasterService
to display an overlay.
How to Display a Toast Overlay
- The
ToasterService
methods accept three parameters that aremessage
,title
, andoptions
. success
,warn
,error
, andinfo
methods return the id of opened toast overlay. The toast can be removed with this id.
How to Display a Toast Overlay With Given Options
Options can be passed as the third parameter to success
, warn
, error
, and info
methods:
life
option is the closing time in milliseconds. Default value is5000
.sticky
option keeps toast overlay on the screen by ignoring thelife
option whentrue
. Default value isfalse
.closable
option displays the close icon on the toast overlay when it istrue
. Default value istrue
.tapToDismiss
option, whentrue
, allows closing the toast overlay by clicking over it. Default value isfalse
.yesText
is the text of the confirmation button. A localization key or localization object can be passed. Default value isAbpUi::Yes
.messageLocalizationParams
is the interpolation parameters for the localization of the message.titleLocalizationParams
is the interpolation parameters for the localization of the title.iconClass
is the CSS class assigned to the icon displayed on a toast overlay.
With the options above, the toast overlay looks like this:
How to Remove a Toast Overlay
The open toast overlay can be removed manually via the remove
method by passing the id
of toast:
How to Remove All Toasts
The all open toasts can be removed manually via the clear
method:
Replacing ToasterService with 3rd party toaster libraries
If you want the ABP Framework to utilize 3rd party libraries for the toasters instead of the built-in one, you can provide a service that implements Toaster.Service
interface, and provide it as follows (ngx-toastr library used in example):
You can use LocalizationService for toaster messages translations.
API
success
Config
namespace can be imported from@abp/ng.core
.Toaster
namespace can be imported from@abp/ng.theme.shared
.
See the
LocalizationParam
type andToaster
namespace
warn
error
info
remove
Removes an open toast by the given id.
clear
Removes all open toasts.