相机未定义

时间:2017-08-04 14:27:52

标签: android angularjs cordova cordova-plugins

我正在尝试实施Cordova Camera插件,以允许用户使用我现有的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 view

<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似乎没有正确加载的任何建议?

软件版本 Cordova 6.0.0 AngularJS 1.3.x

0 个答案:

没有答案