如何从设备中选择多个图像?

时间:2023-01-16 00:33:04

If i create a simple project:

如果我创建一个简单的项目:

ionic start MyApp

And add the ImagePicker plugin:

并添加ImagePicker插件:

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

And simply copy this example www folder into the project and do:

只需将此示例www文件夹复制到项目中即可:

ionic platform add android
ionic build android
ionic run android

Everything is working fine. I can pick multiple images as intended without getting any errors.

一切都很好。我可以按预期选择多个图像而不会出现任何错误。

So far so good. Now i tried to include that into my project so i added the ImagePicker plugin. Now this is my plugin list:

到现在为止还挺好。现在我尝试将其包含在我的项目中,所以我添加了ImagePicker插件。现在这是我的插件列表:

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 it is EXACTLY the SAME controller which i copied from here which worked on the simple test project.

正如您所看到的那样,它完全是我从这里复制的SAME控制器,它处理简单的测试项目。

For any suspect reason this is NOT working. I always get the error:

对于任何可疑的原因,这是行不通的。我总是得到错误:

TypeError: Cannot read property 'getPictures' of undefined

So what's the point of that? Im using EXACT the same code in both projects. In one everything is working and in the other nothing is working. I tried all the examples described here but its always the same.

那有什么意义呢?我在两个项目中使用EXACT相同的代码。在一个方面,一切都在发挥作用,而在另一个方面,没有任我尝试了这里描述的所有例子,但它总是一样的。

2 个解决方案

#1


5  

I checked your project and your index.html is missing cordova.js . So none of your plugins are getting loaded or initialized. Just add the below line in you index.html below where you load ng-cordova.js.

我检查了你的项目,你的index.html缺少cordova.js。因此,没有任何插件被加载或初始化。只需在您加载ng-cordova.js的index.html下面添加以下行。

<script src="cordova.js"></script>

#2


0  

On you example your are injecting $cordovaCamera, however the iconic uses $cordovaImagePicker. Also , in your example your using the object imagePicker from the window object. I don't the window object is what you want.

在你的例子中你注入$ cordovaCamera,但标志性的使用$ cordovaImagePicker。此外,在您的示例中,您使用窗口对象中的对象imagePicker。我不是窗口对象是你想要的。

Try injecting the correct dependency $cordovaImagePicker and use the method $cordovaImagePicker.getPictures from it instead.

尝试注入正确的依赖项$ cordovaImagePicker并使用方法$ cordovaImagePicker.getPictures来代替它。

#1


5  

I checked your project and your index.html is missing cordova.js . So none of your plugins are getting loaded or initialized. Just add the below line in you index.html below where you load ng-cordova.js.

我检查了你的项目,你的index.html缺少cordova.js。因此,没有任何插件被加载或初始化。只需在您加载ng-cordova.js的index.html下面添加以下行。

<script src="cordova.js"></script>

#2


0  

On you example your are injecting $cordovaCamera, however the iconic uses $cordovaImagePicker. Also , in your example your using the object imagePicker from the window object. I don't the window object is what you want.

在你的例子中你注入$ cordovaCamera,但标志性的使用$ cordovaImagePicker。此外,在您的示例中,您使用窗口对象中的对象imagePicker。我不是窗口对象是你想要的。

Try injecting the correct dependency $cordovaImagePicker and use the method $cordovaImagePicker.getPictures from it instead.

尝试注入正确的依赖项$ cordovaImagePicker并使用方法$ cordovaImagePicker.getPictures来代替它。