angularJS file-up-load上传图片

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了angularJS file-up-load上传图片相关的知识,希望对你有一定的参考价值。

                        <div class="form-group">
                            <label class="col-xs-2 control-label col-xs-offset-1">系统图片</label>
                            <div class="col-xs-7">
                                   <div class="input-group" ng-show="YES">
                                
                                    <input class="file-name form-control" type="text" readonly="readonly" id="fileItem" value="{{fileItem.name}}" ng-model="fileItem.name"/>
                                    <div class="input-group-btn">
                                        <input type="file"  accept="image/*"  file-model="myFile" name="certificate" class=‘input-file files fff‘ id="f" onchange="txt.value=this.value"  size="1" hidefocus nv-file-select uploader="uploader"/>
                                        <input type="button" onmousemove="f.style.pixelLeft=event.x-60;f.style.pixelTop=this.offsetTop;"  value="选择图片" size="30" onclick="f.click()" class=" btn-info btn liulan">
                                    </div>
                                  </div>
                                <div class="input-group" ng-show="NO">
                                     <div class="input-group-btn">
                                          <input class="form-control" readonly type="text" name="branchPn_add" name="sysImagePc_add" value="{{sysImagePc_add}}" ng-model="sysImagePc_add" style="width: 82%;">
                                        <input type="button"  value="重新选择" ng-click="chooseAgain()" size="30" class=" btn-info btn liulan">
                                     </div>
                                  </div>
                                  
                                  <div class="input-group imgSrc" ng-show="YESs">
                                         <img ng-src="{{imageSrc}}" id="iSrc" style="max-width:434px;max-height:300px;margin:0 auto;display:block;" />
                                  </div>
                                  <br />
                                <a class="btn btn-info" ng-click=‘UploadFile()‘>上传</a>
                                <a class="btn btn-default" ng-click="EditloadFile()">取消</a>
                            </div>
                            
           
                               
                          </div>


           //新增系统-开始出现弹窗
           $scope.addSystem = function(){
               $scope.YESs = t2;
               $scope.YES = t1;
               $scope.NO = t2;
               $scope.imageSrc = "";
               $(‘#fileItem‘).val("");
//               $scope.createUser_add = $scope.LoginList.employeeName
           }
           //新增系统-重新选择
           $scope.chooseAgain = function(){
               $scope.YES = t1;
               $scope.YESs = t2;
               $scope.NO = t2;
               $scope.fileItem = null;
               $scope.imageSrc = false;
           }
            
           //新增系统-上传图片预览
           $scope.getFile = function () {
               fileReader.readAsDataUrl($scope.file, $scope)
                 .then(function(result) {
                     $scope.sysImagePc_edit = result;
                     $scope.YESs = t1;
                     $scope.sysImagePc_edit = result;
                     $scope.imageSrc = result;
                     $scope.fileItem = $scope.file;
                 });
           };
           
           //新增系统-点击上传
           $scope.uploadStatus = false;
           var uploader = $scope.uploader = new FileUploader({
               url: ‘/FileServlet‘,
               queueLimit: 1,
               removeAfterUpload: true
           });
           uploader.onAfterAddingFile = function(fileItem) {
               $scope.fileItem = fileItem._file;
           };
           uploader.onSuccessItem = function(fileItem, response, status, headers) {
               $scope.uploadStatus = true;
               $scope.sysImagePc_add = response;
               $scope.sysImagePc_edit = response;
               $scope.YESs = t2;
               $scope.YES = t2;
               $scope.NO = t1;
           };
           $scope.UploadFile = function(){
               uploader.uploadAll();
           };
           
           //新增产品-选择图片--取消
           $scope.EditloadFile = function(){
               $scope.YES = t1;
               $scope.YESs = t2;
               $scope.NO = t2;
               $(‘#fileItem‘).val("");
               $scope.fileItem = $scope.sysImagePc_edit;
           };

本文出自 “紫枫5966” 博客,转载请与作者联系!

以上是关于angularJS file-up-load上传图片的主要内容,如果未能解决你的问题,请参考以下文章

AngularJS之WebAPi上传

angularJs中上传图片/文件功能:ng-file-upload

Angularjs - 使用 php 上传文件

AngularJS图片上传功能的实现

如何使用 AngularJS 将文件上传到 Google Drive

在上传 Angularjs 之前预览图片