# new NgxToast()
Wraps Ionic's toast controller with a singleton-friendly API for showing informational, success, warning, and error messages. The class centralizes overlay creation, dismissal handling, and role extraction so application code stays small.
Toast notification helper for Ionic applications.
- Version:
- 1.0.0
- Since:
- 1.0.0
- Implements:
- IDecafToast
Example
```typescript
// Basic usage
const toast = getNgxToastComponent();
await toast.success('Operation completed successfully!');
await toast.error('Something went wrong!');
// With custom options
const toast = getNgxToastComponent({
duration: 5000,
position: 'bottom'
});
await toast.inform('Custom toast message');
// Handling dismissal role
const role = await toast.warn('Are you sure?');
if (role === 'cancel') {
console.log('User cancelled');
}
```
Classes
- NgxToast
Merges the provided options with the default toast configuration so all subsequent notifications share the same baseline settings.
- NgxToast
Merges the provided options with the default toast configuration so all subsequent notifications share the same baseline settings.
Members
DecafToastOptions
# options
Holds the current configuration base that each toast operation reuses before applying action-specific overrides such as color or duration.
Merged toast options used when creating overlays.
DecafToastOptions
# options
Holds the current configuration base that each toast operation reuses before applying action-specific overrides such as color or duration.
Merged toast options used when creating overlays.
Methods
# async create(options) → {Promise.<HTMLIonToastElement>}
Builds and stores the Ionic toast element for later presentation or dismissal. This helper is used internally by the public toast methods.
Creates a toast element.
Parameters:
| Name | Type | Description |
|---|---|---|
options |
Partial.<ToastOptions>
|
Toast configuration options |
Promise that resolves with the toast element
Promise.<HTMLIonToastElement>
# async error(message) → {Promise.<DecafToastRole>}
Presents a toast using the danger color and returns the dismissal role so callers can react to user interaction after the toast closes.
Displays an error toast.
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string
|
The error message to display |
Promise that resolves with the dismissal role
Promise.<DecafToastRole>
Example
```typescript
const role = await toast.error('Failed to save data');
if (role === 'cancel') {
// Handle cancellation
}
```
# async inform(message, optionsopt) → {Promise.<void>}
Presents a neutral message with dark styling and any caller-provided options.
Displays an informational toast.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
message |
string
|
The informational message to display |
||
options |
Partial.<ToastOptions>
|
<optional> |
{} | Additional toast configuration |
Promise that resolves when toast is presented
Promise.<void>
Example
```typescript
await toast.inform('Data loaded successfully');
```
# async show(message, optionsopt) → {Promise.<void>}
Creates the Ionic toast element, dismisses any active toast, and presents the
new overlay. The message argument is merged into the final toast configuration so the
displayed text always reflects the caller input.
Presents a toast using the supplied options.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
message |
string
|
Toast message to display |
|
options |
Partial.<ToastOptions>
|
<optional> |
Toast configuration options |
Promise that resolves when the toast is presented
Promise.<void>
# async success(message) → {Promise.<void>}
Presents a toast with success styling to confirm positive outcomes or completed operations.
Displays a success toast.
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string
|
The success message to display |
Promise that resolves when toast is presented
Promise.<void>
Example
```typescript
await toast.success('Operation completed successfully!');
```
# async warn(message) → {Promise.<DecafToastRole>}
Presents a toast with warning styling and returns the dismissal role after the user closes it.
Displays a warning toast.
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string
|
The warning message to display |
Promise that resolves with the dismissal role
Promise.<DecafToastRole>
Example
```typescript
const role = await toast.warn('This action cannot be undone');
if (role !== 'cancel') {
// Proceed with action
}
```