ngcordova相机图像列表中的数组

时间:2015-10-16 04:14:09

标签: angularjs ionic

我需要将我的base64字符串推入一个空数组,以便我可以在$ http post.i中使用它。当我犯错误时,我不明白。当我使用chome:// inspect /#device我得到ERROR: - 找不到Content-Security-Policy元标记。请在使用cordova-plugin-whitelist插件时添加一个,拍完照片后我会收到net :: ERR_FILE_NOT_FOUND但我可以列出我的照片

HTML

<ion-header-bar class="bar-stable">
    <h1 class="title">OB3 SNAPSHOT</h1>
    <button class="button button-clear button-large ion-ios-camera" style="align:right" ng-click="takePicture()"></button>
</ion-header-bar>
<ion-content>
    <img ng-show="imgURI !== undefined" ng-src="{{imgURI}}">
    <img ng-show="imgURI === undefined" ng-src="http://placehold.it/300x300">
    <!--<button class = "button" ng-click="takePicture()">Take Picture</button>-->
    <ul class="list">
        <li class="item" ng-repeat="i in myImage">
            <img ng-src="{{baseURL+i}}" ng-click="clickImage()">
        </li>
    </ul>
</ion-content>

AngularJS

exampleApp.controller("ExampleController", function($scope, $cordovaCamera) {
    $scope.myImage = [];
    $scope.baseURL = 'data:image/jpeg;base64,';

    $scope.clickImage = function() {
        var postObject = {
            data: {
                "width": 32,
                "height": 32,
                "mimetype": "image/png",
                "name": "Image",
                "bindaryData": $scope.myImage[0]
            }
        }

        $http.post(" url",
                postObject)
            .success(function(response) {
                $scope.names = response.response.data;
                console.log(response);
                console.log(response.response.data);
            })

        .error(function(response) {
            console.log(response);
            alert('post is error');
        });
    };


    $scope.takePicture = function() {
        navigator.camera.getPicture(onSuccess, onFail, {
            quality: 75,
            targetWidth: 320,
            targetHeight: 320,
            destinationType: 0
        });

        function onSuccess(imageData) {
            $scope.imgURI = imageData;
            $scope.myImage.push($scope.imgURI);
            $scope.$apply();
        }

        function onFail(message) {
            alert('Failed because: ' + message);
        }

    };
});

1 个答案:

答案 0 :(得分:1)

实际上推动 $ scope.imgURI 工作正常。但是您的视图没有更新。请拍两张照片。然后您就可以理解您的问题了。通过添加 {{1} } )将解决您的问题

试试这段代码,

<强>控制器

<nav class="navbar navbar-default navbar-static-top" data-spy="affix" data-offset-top="397" role="navigation">

<强> HTML

$scope.$apply(

<强> Refer