一、安装ngCordova

1.在git Bash 中 输入:
bower install ngCordova

2.接着,将ng-cordova.js 或者 ng-cordova.min.js文件include到我们的index.html。
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>


二、在angular中添加ngCordova依赖
angular.module('myApp', ['ngCordova'])

三、插件的使用
例如:相机插件
1.首先我们还是要安装插件的:
cordova plugin add cordova-plugin-camera
调用相机插件
cordova plugin add cordova-plugin-barcodescanner
调条形码扫描
cordova plugin add phonegap-plugin-barcodescanner
调二维码扫描
cordova plugin add jpush-phonegap-plugin --variable API_KEY=8325fdc6cbc21117a5feb165
极光推送

2.页面中:
<ion-view view-title="Dashboard">
<ion-content class="padding">
<h2> Camera Test </h2>
<img id="imageFile" src="./img/ionic.png" width="100px" height="100px"/>
<button ng-click="openCamera()">openCamera</button>
</ion-content>
</ion-view>

3.在controllers.js中修改“DashCtrl”这个controller:
angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope, $cordovaCamera) {
document.addEventListener("deviceready", function () {
var options = {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 100,
targetHeight: 100,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation:true
};
$scope.openCamera= function(){
$cordovaCamera.getPicture(options).then(function(imageData) {
var image = document.getElementById('imageFile');
image.src = "data:image/jpeg;base64," + imageData;
}, function(err) {
// error
});
}, false;
})
})

 

posted on 2016-12-07 11:32  逆鳞随行  阅读(255)  评论(0编辑  收藏  举报