微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如果我创建一个简单的项目:
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复制的SAME控制器,该控制器用于简单的测试项目.

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

TypeError: Cannot read property 'getPictures' of undefined

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

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

原文地址:https://www.jb51.cc/angularjs/141228.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐