Cordova-plugin-camera not working

Continuing the discussion from Cordova Camera Plugin Not Working w/ AngularJS:

I’m using VS 2015 so i installed the plugin directly within the IDE in config.xml
I’m new to angular.
services.js

.factory('Camera', function ($q) {

    return {
        getPicture: function (options) {
            var q = $q.defer();

            navigator.camera.getPicture(function (result) {
                q.resolve(result);
            }, function (err) {
                q.reject(err);
            }, options);

            return q.promise;
        }
    }

})

controller.js

   $scope.takePicture = function (options) {

            var options = {
                quality: 75,
                targetWidth: 200,
                targetHeight: 200,
                sourceType: 1
            };

            Camera.getPicture(options).then(function (imageData) {
                $scope.picture = imageData;
            }, function (err) {
                console.log(err);
            });

        };

myPage.html

 <a class="button button-full  ion-ios-camera button-outline button-royal" ng-click="takePicture()" >

                            </a>

Why dont you try using ngCordova.

All you have to do is inject $cordovaCamera as a dependency and change Camera.getPicture(options) in controller to $cordovaCamera.getPicture(options)

Refer this link cordova camera plugin using ngCordova

1 Like

Now I’m using $cordovaCamera but when injected the dependency white screen comes on debugging.

.controller('AppCtrl', function ($scope, $ionicModal, $timeout, $ionicPopup,
$cordovaCamera) {

 

    // Open Camera
    //take picture
    $scope.takePicture = function (options) {

        var options = {
            quality: 75,
            targetWidth: 200,
            targetHeight: 200,
            sourceType: 1
        };


        $cordovaCamera.getPicture(options).then(function (imageData) {
            $scope.picture = imageData;
        }, function (err) {
            console.log(err);
        });

};

----code of other modules----

Thanks For Your Help Please Check the Comment Below.

I mean to say above comment :stuck_out_tongue:

I was hitting my head when you mentioned comment below…

Well, if you are using ionic serve or web browser to debug, then it won’t work. You have to use device or emulator. I would say using device is much better

:smile: LOL! … I thought it will show my comment below yours anyways I’m using a physical Android Device. I think problem is somewhere in the directory because in my previous project i did the same and camera was working fine but this time it is not even showing the camera view. :angry:

Thanks bTw will find out the problem and solve it.

Did yu follow these installation steps

Did you try to look at console log errors

Yes i did that step by step it was a compatibility issue with the current version of angular…with earlier version it is working fine. :smiley:

Good to know that you solved it :slight_smile:

1 Like

Ionic 3 and Angular 2: Using the Native Camera, Take Multiple Photos with Delete Action.