【发布时间】:2017-08-04 14:27:51
【问题描述】:
我正在尝试实现 Cordova 相机插件,以允许用户使用我现有的 Cordova/AngularJS 移动应用程序使用他们的相机拍照。
我正在尝试使用本文中的方法(这适用于新的 Cordova 应用程序) http://sourcefreeze.com/cordova-camera-plugin-example-using-ionic-framework/
我添加了 ngCordova.min.js gruntfile,当应用程序通过 gulp 构建过程时,该文件将该文件添加到应用程序。
在 app.js 中,我添加了如下模块(请注意,由于它的长度,我没有添加整个 app.js)
// app.js
var hqApp = angular.module('hqApp', [ 'hqControllers', 'hqFilters', 'hqServices', 'hqDirectives',
'ngMaterial', 'ngCordova' ]); // ngCordova has been added to the array
// html 视图
<button class="button button-full" ng-click="uploadFromCamera()">
Take Photo
</button>
<img ng-show="imgURI !== undefined" ng-src="{{imgURI}}" style="text-align: center">
// 控制器(由于长度而不是整个控制器)
hqControllers.controller(
'PostController',
['$http', '$localStorage', '$location', '$modal', '$routeParams', '$rootScope', '$scope', '$timeout', 'Upload', '$window', 'CharacterCountFilterFilter', 'ApplicationService', function(ApiService, ConfirmDialog, ContentReview, FeedService, $http, $localStorage, $location, $modal, $q, $routeParams, $rootScope, $scope, snackbar, $timeout, Upload, $window, CharacterCountFilterFilter, ApplicationService, $cordovaCamera) {
// when button click hits this function
$scope.uploadFromCamera = function () {
console.log('Upload from Camera');
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.imgURI = "data:image/jpeg;base64," + imageData;
}, function (err) {
});
}
每当我点击“拍照”按钮时,我都会在 console.log 中看到以下内容
ReferenceError: Camera is not defined at h.$scope.uploadFromCamera
关于 ngCordova 似乎无法正确加载的任何建议?
软件版本 科尔多瓦 6.0.0 AngularJS 1.3.x
【问题讨论】:
-
显示链接 Cordova 的代码
标签: android angularjs cordova cordova-plugins