繁体   English   中英

使用Angular.js上传后无法显示图像

[英]Image can not be displayed after upload using Angular.js

我有一个问题。 从Angular.js中选择ng-file-upload后,我无法显示图像。 我必须在这里上传多个文件。 我在下面解释我的代码。

<div ng-repeat="mul in mulImage">
    <div class="input-group bmargindiv1 col-md-12">
      <span class="input-group-addon ndrftextwidth text-right" style="width:180px">Image{{$index+1}}:</span>
      <div>

        <input type="file" class="filestyle form-control" data-size="lg" name="upload_{{$index}}" id="bannerimage_{{$index}}" ng-model="file" ngf-pattern="'image/*'" accept="image/*" ngf-max-size="2MB" custom-on-change="uploadFile" ngf-select="onFileSelect($index,$file);">
        <div style="clear:both;"></div>

      </div>
      <span class="input-group-btn" ng-show="mulImage.length>0">
      <img ng-src="{{attchImage}}" name="pro" border="0" style="width:32px; height:32px; border:#808080 1px solid;" ng-if="mul.image !=null">
            <input type="button" class="btn btn-success" name="plus" id="plus" value="+" ng-click="addNewImageRow(mulImage);" ng-show="$last"> <input type="button" class="btn btn-danger" name="minus" id="minus" value="-"  ng-show="mulImage.length>1" ng-click="deleteNewImageRow(mulImage,$index);">
       </span>
    </div>
  </div>

我的控制器端代码如下。

$scope.uploadFile = function(event) {
    console.log('event', $scope.mulImage.length);
    var files = event.target.files;
    for (var i = 0; i < files.length; i++) {
      var file = files[i];
      var reader = new FileReader();
      reader.onload = $scope.imageIsLoaded;
      reader.readAsDataURL(file);
    }
  };
  $scope.imageIsLoaded = function(e) {
    $scope.$apply(function() {
      $scope.attchImage = e.target.result;
    });
  }

在这里,我需要在选择图像后将其显示在图像标签中,但操作失败。 这是我的代码。 请帮我解决这个问题。

您在视图中使用了“ onFileSelect”并定义了$ scope.onFileSelect1。 如果我对其进行编辑,则为我运行plunkersample。 还是我错过了什么?

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM