Dialogs
This plugin gives you ability to access and customize the device native dialogs.
Requires Cordova plugin: cordova-plugin-dialogs
. For more info, please see the Dialogs plugin docs.
Repo: https://github.com/apache/cordova-plugin-dialogs
Installation
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-dialogs $ npm install --save @ionic-native/dialogs@4
- Add this plugin to your app's module
Supported platforms
- Amazon Fire OS
- Android
- Browser
- iOS
- Windows
Usage
import { Dialogs } from '@ionic-native/dialogs';
constructor(private dialogs: Dialogs) { }
...
this.dialogs.alert('Hello world')
.then(() => console.log('Dialog dismissed'))
.catch(e => console.log('Error displaying dialog', e));
Instance Members
alert(message, title, buttonName)
Shows a custom alert or dialog box.
Param | Type | Details |
---|---|---|
message |
string
|
Dialog message. |
title |
string
|
Dialog title. (Optional, defaults to Alert)Optional |
buttonName |
string
|
Button name. (Optional, defaults to OK)Optional |
Returns: Promise<any>
Returns a blank promise once the user has dismissed the alert.
confirm(message, title, buttonLabels)
Displays a customizable confirmation dialog box.
Param | Type | Details |
---|---|---|
message |
string
|
Dialog message. |
title |
string
|
Dialog title. (Optional, defaults to Confirm)Optional |
buttonLabels |
Array<string>
|
Array of strings specifying button labels. (Optional, defaults to [OK,Cancel])Optional |
Returns: Promise<number>
Returns a promise that resolves the button index that was clicked, or 0 if the user has dismissed the dialog by clicking outside the dialog box. Note that the index use one-based indexing.
prompt(message, title, buttonLabels, defaultText)
Displays a native dialog box that is more customizable than the browser’s prompt function.
Param | Type | Details |
---|---|---|
message |
string
|
Dialog message.Optional |
title |
string
|
Dialog title. (Optional, defaults to Prompt)Optional |
buttonLabels |
Array<string>
|
Array of strings specifying button labels. (Optional, defaults to ["OK","Cancel"])Optional |
defaultText |
string
|
Default text box input value. (Optional, Default: empty string)Optional |
Returns: Promise<DialogsPromptCallback>
Returns a promise that resolves an object with the button index clicked and the text entered
beep(times)
The device plays a beep sound.
Param | Type | Details |
---|---|---|
times |
numbers
|
The number of times to repeat the beep. |
DialogsPromptCallback
Param | Type | Details |
---|---|---|
buttonIndex |
number
|
The index of the pressed button. (Number) Note that the index uses one-based indexing, so the value is 1, 2, 3, etc. |
input1 |
string
|
The text entered in the prompt dialog box. (String) |