How to select multiple images from a device?

If I create a simple project:

ionic start MyApp 

And add the ImagePicker plugin:

 ionic plugin add https://github.com/wymsee/cordova-imagePicker.git -save 

And just copy this example www folder into the project and execute:

 ionic platform add android ionic build android ionic run android 

Everything is working fine. I can select multiple images for their intended purpose without any errors.

So far so good. Now I tried to include this in my project, so I added the ImagePicker plugin. Now this is my list of plugins:

 ionic plugin ls com.synconset.imagepicker 1.0.6 "ImagePicker" cordova-plugin-camera 1.1.0 "Camera" cordova-plugin-device 1.0.0 "Device" cordova-plugin-dialogs 1.1.0 "Notification" cordova-plugin-splashscreen 2.0.0 "Splashscreen" cordova-plugin-statusbar 1.0.0 "StatusBar" cordova-plugin-vibration 1.1.0 "Vibration" cordova-plugin-whitelist 1.0.0 "Whitelist" 

I created a new module:

 angular.module('App.ImageSelect', []) .config(function ($stateProvider, $urlRouterProvider) { $stateProvider.state('app.imageSelect', { url: "/products/prints/pola/imageSelect", views: { 'menuContent': { templateUrl: "modules/products/prints/pola/imageSelect/imageSelect.html", controller: 'ImageSelectController' } } }); }) .controller('ImageSelectController', function ($scope, $cordovaImagePicker) { $scope.images = []; $scope.selectImages = function () { $cordovaImagePicker.getPictures( function (results) { for (var i = 0; i < results.length; i++) { console.log('Image URI: ' + results[i]); $scope.images.push(results[i]); } if (!$scope.$$phase) { $scope.$apply(); } }, function (error) { console.log('Error: ' + error); } ); }; }); 

As you can see, EXACTLY, SAME, is the controller that I copied from here that worked on a simple test project.

For any suspicious reason, this does NOT work. I always get the error:

 TypeError: Cannot read property 'getPictures' of undefined 

So what is this? I use EXACT the same code in both projects. In one, everything works, and in the other, nothing works. I tried all the examples described here, but its always the same.

+7
angularjs cordova ionic-framework ngcordova
source share
2 answers

I checked your project and your index.html is missing cordova.js . Therefore, none of your plugins are loaded or initialized. Just add the line below to index.html below, where you download ng-cordova.js.

 <script src="cordova.js"></script> 
+5
source share

In your example, you enter $cordovaCamera , however the signed one uses $cordovaImagePicker . Also, in your example, you are using the imagePicker object from the window object. I am not a window object - this is what you want.

Try to introduce the correct $cordovaImagePicker and use the $cordovaImagePicker.getPictures method $cordovaImagePicker.getPictures .

0
source share

All Articles