Utility methods to create different kinds of notifications. There are three methods available:
ons.notification.alert()
ons.notification.confirm()
ons.notification.prompt()
ons.notification.toast()
It will automatically display a Material Design dialog on Android devices.The $ons.notification
object contains some useful methods to easily show alerts, confirmation dialogs and prompts:
1.
$ons.notification.alert(message, options)
2.
$ons.notification.confirm(message, options)
3.
$ons.notification.prompt(message, options)
4.
$ons.notification.toast(message, options)
They all return a Promise
object that can be used to handle the input from the user.
$ons.notification.confirm('Are you ready?')
.then((response) => {
// Handle response.
});
Notifications can also be created using VOnsDialog
, VOnsAlertDialog
and VOnsToast
instead of $ons.notification
.
Signature | Description |
---|---|
alert(message [, options] | options) |
Display an alert dialog to show the user a message. The content of the message can be either simple text or HTML. It can be called in the following ways:
Must specify either |
confirm(message [, options] | options) |
Display a dialog to ask the user for confirmation. Extends
Must specify either |
prompt(message [, options] | options) |
Display a dialog with a prompt to ask the user a question. Extends
Must specify either |
toast(message [, options] | options) |
Display a simple notification toast with an optional button that can be used for simple actions. It can be called in the following ways:
|
Display an alert dialog to show the user a message. The content of the message can be either simple text or HTML. It can be called in the following ways:
ons.notification.alert(message, options);
ons.notification.alert(options);
Must specify either message
or messageHTML
.
Returns: Will resolve to the index of the button that was pressed or -1
when canceled.
Display a dialog to ask the user for confirmation. Extends alert()
parameters.
The default button labels are "Cancel"
and "OK"
but they can be customized.
It can be called in the following ways:
ons.notification.confirm(message, options);
ons.notification.confirm(options);
Must specify either message
or messageHTML
.
Returns: Will resolve to the index of the button that was pressed or -1
when canceled.
Display a dialog with a prompt to ask the user a question. Extends alert()
parameters.
It can be called in the following ways:
ons.notification.prompt(message, options);
ons.notification.prompt(options);
Must specify either message
or messageHTML
.
Returns: Will resolve to the input value when the dialog is closed or null
when canceled.
Display a simple notification toast with an optional button that can be used for simple actions. It can be called in the following ways:
ons.notification.toast(message, options);
ons.notification.toast(options);
Returns: Will resolve when the toast is hidden.
If you have any questions, use our Community Forum or talk to us on Discord chat. The Onsen UI team and your peers in the community will work together to help solve your issues.
For bug reports and feature requests use our GitHub Issues page.