Dialogs

Improve this doc

$ ionic plugin add cordova-plugin-dialogs
$ npm install --save @ionic-native/dialogs

Repo: https://github.com/apache/cordova-plugin-dialogs.git

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.

Supported platforms

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)

buttonName string

Button name. (Optional, defaults to OK)

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)

buttonLabels Array<string>

Array of strings specifying button labels. (Optional, defaults to [OK,Cancel])

Returns: Promise<number> Returns a promise that resolves the button index that was clicked. 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.

title string

Dialog title. (Optional, defaults to Prompt)

buttonLabels Array<string>

Array of strings specifying button labels. (Optional, defaults to ["OK","Cancel"])

defaultText string

Default textbox input value. (Optional, Default: empty string)

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)

API

Native

General