ng-cordova
环境配置
1.执行以下命令
bower install ngCordova
2.引用文件(在引用cordova.js之前引用)
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
3.注入模块
angular.module('App', ['ngCordova'])
4.使用
添加需要用的插件
cordova plugin add ...
在使用的serveic/controller注入要用的插件
$cordovaDialogs (弹出对话框,提示框,输入框)
添加
cordova plugin add cordova-plugin-dialogs
使用
alert(message, title, buttonName)
confirm(message, title, buttonArray)
prompt(message, title, buttonArray, defaultText)
beep(repetitions)
demo
app.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);
});