ngCordova : $cordovaCamera is undefined


#1

Hi there,

I’m trying to implement picture capture with ngCordova. So I followed this list

  1. Install apache cordova plugin

  2. Add ios param in config.xml

  3. download js ng-cordova and link it to my index

  4. declare ‘ngCordova’ plugin in my app

  5. Implement camera test in my controller

    $scope.takePicture = function() {

    if (typeof $cordovaCamera == ‘undefined’)
    {$scope.photo = ‘http://placekitten.com/320/320’;
    console.log(‘Camera not found’);}
    else
    {
    $cordovaCamera.getPicture({
    quality: 75,
    targetWidth: 320,
    targetHeight: 320,
    saveToPhotoAlbum: false
    }).then(function(imageURI) {
    $scope.photo = imageURI;
    }, function(err) {
    console.error(‘Unable to take pic’, err);
    alert(‘Unable to take picture’);
    });
    }
    }

  6. No error in Web console, except $cordovaCamera is undefined, that is normal I guess

But when I try to test it on IOS device, I get exactly the same thing than web : $cordovaCamera is undefined.

Any advice on this ?


#2

Did you add $cordovaCamera it in your controller declaration ? Just like:

my_app.controller('MyCtrl', function($scope, $cordovaCamera) {
  // Your picture function here
});

#3

Yes, I put it. I’ve tested on android and on iOS it doesn’t work


#4

Testing with phonegap code from ducmentation

    function capturePhoto() {
  // Take picture using device camera and retrieve image as base64-encoded string
  navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
    destinationType: destinationType.DATA_URL });
}

It works like a charm on both IOS and Android, I think I miss something with ng-cordova.


#5

How did you get the ng-cordova.js file ? The custom build had generated an invalid file for me… I had to download the file from github and it worked.


#6

Yes, I read your post because I got a ‘ngCordova’ module not found error. So I directly downloaded the raw version from Github https://github.com/driftyco/ng-cordova/blob/master/dist/ng-cordova.js and this error disappeared.


#7

Actually, if you put in your angular app “ngCordova”, but launch a custom build for the camera plugin, the module will be named “ngCordova.plugins.camera”, so that’s the reason why it wasn’t found.


#8

Interesting, I will give a try to test ngCordova.plugins.camera with a custom build
I keep you informed


#9

The problem is that with a custom build the ngCordova module is not created.


#10

OK it works guys.
I downloaded a custom build, and declare “ngCordova.plugins.camera” plugin.
Xcode told me it doesn’t find Camera device, so I removed cordova camera plugin and add it again (a kind of refresh) and camera capture works fine.

Thanks for your support !