CordovaShims.Services.Dialogs Class
Service that allows for displaying native dialogs for user interaction.
Configuration and setup of the service is done in an initializer:
import DialogsService from 'cordova-shims/services/dialogs';
export function initialize(container, application) {
application.register('service:dialogs', DialogsService);
application.inject('route', 'dialogs', 'service:dialogs');
}
export default {
name: 'dialogs-service',
initialize: initialize
};
The service has an interface for defining custom fallback methods for each dialog type.
- alertFallback
- confirmFallback
- promptFallback
If your app targets both browser and native platforms, you should provide your own implementation of these fallbacks methods. There are simple default methods defined to get you started quickly.
Methods
alert
-
options
Display an alert box to the user with a title, message and a customizable button name.
Example:
DialogsService.create().alert({
title: 'Something important',
message: 'This just happened!',
button: 'OK'
});
Parameters:
-
options
Object-
title
StringTitle for the alert box
-
message
StringMessage to show in the alert box
-
button
StringText for the button that dismisses the alert box
-
Returns:
A promise that will resolve when alert is dismissed.
confirm
-
options
Display a confirm box to the user with a title, message and customizable button names.
Example:
DialogsService.create().confirm({
title: 'Something important',
message: 'This just happened!',
buttons: [
'OK',
'Cancel'
]
});
Parameters:
-
options
Object-
title
StringTitle for the confirm box
-
message
StringMessage to show in the confirm box
-
buttons
ArrayText for the button that dismisses the confirm box
-
Returns:
A promise that will resolve with the index of the button pressed (1-indexed).
prompt
-
options
Display a prompt to the user with a title, message, text input and a customizable button name.
Example:
DialogsService.create().prompt({
title: 'Please provide some info',
message: 'We need to know something.',
defaultText: 'foo',
buttons: [
'OK',
'Cancel'
]
});
Parameters:
-
options
Object-
title
StringTitle for the confirm box
-
message
StringMessage to show in the confirm box
-
buttons
ArrayText for the button that dismisses the confirm box
-
Returns:
A promise that will resolve with the following:
{
text: "{text-from-input}",
buttonIndex: 1 // Index of the button pressed
}
Properties
alertFallback
Function
Hook that gets triggered if the plugin API is not available. Useful for handling dialogs in a browser environment.
confirmFallback
Function
Hook that gets triggered if the plugin API is not available. Useful for handling dialogs in a browser environment.
promptFallback
Function
Hook that gets triggered if the plugin API is not available. Useful for handling dialogs in a browser environment.