$cordovaImagePicker not defined [solved]


#1

I am trying to use the image picker plugin with ionic but it does not work for me.

I followed the instructions from here: http://ngcordova.com/docs/plugins/imagePicker/

I executed: cordova plugin add https://github.com/wymsee/cordova-imagePicker.git
Successfull installation with android platform, no problem.

But when I try to use the plugin in one controlled, it does not work (im am using the command “ionic run android -l -c” to developing my app).

app.controller(‘ProfileCtrl’, ["$scope", “$cordovaImagePicker”, function($scope, cordovaImagePicker) {

$scope.$on("$ionicView.enter", function(event) {
    
    var options = {
    maximumImagesCount: 10,
    width: 800,
    height: 800,
    quality: 80
    };
    $cordovaImagePicker.getPictures(options)
    .then(function (results) {
    for (var i = 0; i < results.length; i++) {
        console.log('Image URI: ' + results[i]);
    }
    }, function(error) {
    // error getting photos
    });
    
});

}]);

I got this error:

console-via-logger.js:173 ReferenceError: $cordovaImagePicker is not defined
at controllers.js:405
at Scope.$emit (ionic.bundle.js:24924)
at Object.emit (ionic.bundle.js:50629)
at transitionComplete (ionic.bundle.js:50586)
at onReflow (ionic.bundle.js:50566)
at ionic.bundle.js:26541
at completeOutstandingRequest (ionic.bundle.js:14226)
at ionic.bundle.js:14498

Do I need to add any other reference in the code to use this plugin??

This is my plugins/android.json

{
“prepare_queue”: {
“installed”: [],
“uninstalled”: []
},
“config_munge”: {
“files”: {}
},
“installed_plugins”: {
“cordova-plugin-console”: {
“PACKAGE_NAME”: “com.mypackagename”
},
“cordova-plugin-device”: {
“PACKAGE_NAME”: “com.mypackagename”
},
“cordova-plugin-splashscreen”: {
“PACKAGE_NAME”: “com.mypackagename”
},
“cordova-plugin-statusbar”: {
“PACKAGE_NAME”: “com.mypackagename”
},
“cordova-plugin-whitelist”: {
“PACKAGE_NAME”: “com.mypackagename”
},
“ionic-plugin-keyboard”: {
“PACKAGE_NAME”: “com.mypackagename”
},
“cordova-plugin-inappbrowser”: {
“PACKAGE_NAME”: “com.mypackagename”
},
“cordova-plugin-image-picker”: {
“PACKAGE_NAME”: “com.mypackagename”
}
},
“dependent_plugins”: {}
}

I tried this solutions:

And to remove and add the same plugin but it does not work.

Please help


#2

Its not available in the browser, so you should do a check before you use it. You can only test most plugins on a device.


#3

I solved the issue.

I put here my workaround to solve the problem:

  • remove plugin
  • update cordova
  • update cordova android / ios platform
  • reinstall the plugin

Now works. Ionic thank you.


#4

inject $cordovaImagePicker instead of cordovaImagePicker