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

标签 angularjs cordova ionic-framework ngcordova

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

ionic start MyApp

并添加 ImagePicker插入:
ionic plugin add https://github.com/wymsee/cordova-imagePicker.git -save

只需复制this example www folder进入项目并执行:
ionic platform add android
ionic build android
ionic run android

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

到现在为止还挺好。现在我尝试将它包含到我的项目中,所以我添加了 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"

我创建了一个新模块:
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);
            }
        );
    };
});

如您所见,它与我从 here 复制的 Controller 完全相同它适用于简单的测试项目。

由于任何可疑的原因,这不起作用。我总是得到错误:
TypeError: Cannot read property 'getPictures' of undefined

那有什么意义呢?我在两个项目中使用完全相同的代码。一方面,一切都在工作,另一方面,一切都在工作。我尝试了所有描述的示例here但它总是一样的。

最佳答案

我检查了您的项目,发现您的 index.html 丢失了 cordova.js .所以你的插件都没有被加载或初始化。
只需在加载 ng-cordova.js 的下面的 index.html 中添加以下行。

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

关于angularjs - 如何从设备中选择多个图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30624972/

相关文章:

android - 如何更改 PhoneGap 的屏幕大小?

angularjs - Cordova/Ionic Firebase Auth 持久登录

html - 如何覆盖 element.style 属性? (溢出: hidden)

javascript - 使用 ng-class 单击时不附加类

javascript - ng-if 内的 Angular js

angularjs - 在具有多个 View 的tomcat中配置angularjs应用程序

node.js - 我的 npm 已损坏 - 无法读取未定义的属性 'get'

cordova - PhoneGap 相机在拍摄图像后无法确认

android - 将 cordova 项目升级到 visual studio 2015 后,Ripple 找不到 config.xml

angularjs - Angular.js : Wrapping elements in a nested transclude