$cordovaDialogs显示一个系统提示对话框,可以显示一个普通cordova对话框,也可以显示显示一个带有指定消息和取消及取消按钮的对话框(可以自定义两个按钮的名称),也可以显示显示可提示用户进行输入的对话框
$cordovaDialogs cordova对话框插件
$cordovaDialogs显示一个系统提示对话框,Trigger alert, confirm, and prompt windows, or send beeps (beep, beep!)
cordova plugin add cordova-plugin-dialogs
方法(Methods)
alert(message, title, buttonName)
$cordovaDialogs显示一个普通对话框
参数 | 类型 | 说明 |
---|---|---|
message | String | 对话框提示的一段文字 |
title | String | 对话框标题 默认:alert |
buttonName | String | 对话框按钮名称 默认:ok |
confirm(message, title, buttonArray)
$cordovaDialogs显示一个带有指定消息和取消及取消按钮的对话框(可以自定义两个按钮的名称)
参数 | 类型 | 说明 |
---|---|---|
message | String | 对话框提示的一段文字 |
title | String | 对话框标题 默认:alert |
buttonArray | Array | 按钮名名称 是一个数组 默认:[‘ok’,’Cancel’] |
返回值 Integer 1或2取决于你点击了哪一个按钮
prompt(message, title, buttonArray, defaultText)
显示可提示用户进行输入的对话框
参数 | 类型 | 说明 |
---|---|---|
message | String | 对话框提示的一段文字 |
title | String | 对话框标题 默认:alert |
buttonArray | Array | 按钮名名称 是一个数组 如:[‘ok’,’Cancel’] |
defaultText | String | 用户输入提示信息 |
返回值 Object 用于接受用户输入:result.input1 判断用户点击那哪一个按钮 返回一个索引:result.buttonIndex
beep(repetitions)
显示可提示用户进行输入的对话框
参数 | 类型 | 说明 |
---|---|---|
repetitions | Integer | 设置弹出对话框延迟以秒为单位 |
代码实例
module.controller('MyCtrl', function($scope, $cordovaDialogs) {
$cordovaDialogs.alert('message', 'title', 'button name')
.then(function() {
// callback success
});
$cordovaDialogs.confirm('message', 'title', ['button 1','button 2'])
.then(function(buttonIndex) {
// no button = 0, 'OK' = 1, 'Cancel' = 2
var btnIndex = buttonIndex;
});
$cordovaDialogs.prompt('msg', 'title', ['btn 1','btn 2'], 'default text')
.then(function(result) {
var input = result.input1;
// no button = 0, 'OK' = 1, 'Cancel' = 2
var btnIndex = result.buttonIndex;
});
// beep 3 times
$cordovaDialogs.beep(3);
});