Zabs
Zabs

Reputation: 14142

Camera is not defined

I am trying to implement the Cordova Camera plugin to allow for users to take photos using their camera using my existing Cordova/AngularJS mobile app.

I am trying to use the methods found in this article (and this works fine for a new fresh Cordova application) http://sourcefreeze.com/cordova-camera-plugin-example-using-ionic-framework/

I have added the ngCordova.min.js gruntfile that adds this file to the application when it goes through the gulp build process.

Within the app.js I have added the module as below (please note I have not added the entire app.js due to its length)

// 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">

// controller (not the whole controller due to length)

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) {

    });
}

Whenever I click the 'Take Photo' button I get the following in the console.log

ReferenceError: Camera is not defined at h.$scope.uploadFromCamera

Any suggestions why the ngCordova doesn't seem to be loading correctly?

Software versions Cordova 6.0.0 AngularJS 1.3.x

Upvotes: 0

Views: 985

Answers (1)

Zabs
Zabs

Reputation: 14142

I had a build script that wasn't linking to ngCordova - fixed now

Upvotes: 0

Related Questions