ionic 使用ngcordova插件

需要安装ngcordova的js文件,下载zip包,把ng-cordova.js和copy进相应的目录,在页面中引入即可


Install

Get the Source File

You can use bower to install ngCordova like so or download the zip file here, and locate the .js file in the dist folder:

$ bower install ngCordova

Include ng-cordova.js or ng-cordova.min.js in your index.html file before cordova.js and after your AngularJS / Ionic file (since ngCordova depends on AngularJS).

<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
Inject as an Angular dependency

Then, include ngCordova as a dependency in your angular module:

angular.module('myApp', ['ngCordova'])
Wrap each plugin call with the deviceready event - important !

Before each plugin you must check if your device has fully loaded, and if the plugins are available using a native cordova event called deviceready. Implement it like so:

document.addEventListener("deviceready", function () {
  $cordovaPlugin.someFunction().then(success, error);
}, false);

// OR with IONIC

$ionicPlatform.ready(function() {
  $cordovaPlugin.someFunction().then(success, error);
});
Add the plugin to your project using the Cordova CLI

Now you can add plugins to your cordova project, and use the ngCordova API detailed below:

cordova plugin add ...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值