cordova的插件怎么引用

2025-04-14 15:18:07
推荐回答(1个)
回答1:

4、ng-cordova安装与使用
4.1、下载ng-cordova
bower install ngCordova

4.2、引入ng-cordova.js文件

把 ng-cordova.js 或者 ng-cordova.min.js引入index.html中并放在cordova.js之前, AngularJS Ionic 文件之后 (因为ngCordova d依赖AngularJS).

4.4、引入ng-cordova的依赖
在主程序的app.js中引入ng-cordova的依赖
angular.module('myApp', ['ngCordova'])

4.5、添加插件到你的Cordova CLI环境中

cordova plugin add ...

4.6、使用
要在检查设备准备完毕之后使用
document.addEventListener("deviceready", function () {
$cordovaPlugin.someFunction().then(success, error);
}, false);

// OR with IONIC

$ionicPlatform.ready(function() {
$cordovaPlugin.someFunction().then(success, error);
});

不过我测试过,因为已经run过了,你的各种功能肯定在这之后,所以之后在哪用都可以。不过要是有些功能是启动应用就要有,还是要写在这里面的。
?

angular.module('starter', ['ionic', 'route','config','global','commonJs','ngCordova'])

.run(['$ionicPlatform','$rootScope', '$location', '$timeout', '$ionicHistory','CommonJs','$cordovaToast',function($ionicPlatform,$rootScope, $location, $timeout, $ionicHistory,CommonJs,$cordovaToast) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleLightContent();
}
});

}]);