我有一个示例离子应用程序,只需从手机拍照。 我在tab-dash.html tab-dash.html中有一个按钮 我有一个控制器来拍照逻辑controllers.js 我已经包含了ngCordova,所有必需的cordova插件,但是当我点击手机拍照时,只有控制台日志有效,而不是实际拍照。这可能有什么不对?您可以访问完整的仓库https://github.com/7seven7lst/Ionic_test。下面是代码的片段
angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope) {
$scope.inject = ['$cordovaCamera','$cordovaGeolocation','$cordovaFileTransfer'];
$scope.log=function(){
console.log('hello~~~');
};
$scope.takePicture = function() {
console.log('taking pictures ....');
var options = {
quality : 75,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 300,
targetHeight: 300,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function(imageData) {
$scope.imageURI = imageData;
console.log('$scope.image is ', $scope.imageURI);
}, function(error){
console.log('the error is ', error);
})
};
})
答案 0 :(得分:1)
.controller('DashCtrl', function($scope)
将上述行更改为此内容,添加 $ cordovaCamera
.controller('DashCtrl', function($scope,$cordovaCamera)