angular +H5 上传图片 与预览图片

2021-07-01 15:06

阅读:579

标签:identity   script   card   ng-model   sub   conf   default   button   dex   

//index.html

























...





...







...












  service.js

var uploadFile = function(dataParam,successFn,errFun){
          $http({
              method: ‘POST‘,
              url: configuration.apiBaseUrl+‘/api/tms/upload/uploadFile‘,
              data: dataParam,
              headers: {‘Content-Type‘: undefined},
              transformRequest: angular.identity
          }).success(function (data) {
              if(typeof successFn ===‘function‘){
                  successFn(data);
              }
          }).error(function (data) {
              if(typeof errFun === ‘function‘){
                  errFun(data);
              }
          });
      };

  3:controller.js

 function save(frontIdCard,backIdCard,photoDriverCard) {
            var fd = new FormData();
            if(frontIdCard){
                fd.append("frontIdCard", frontIdCard);
            }
            if(backIdCard){
                fd.append("backIdCard", backIdCard);
            }
            if(photoDriverCard){
                fd.append("photoDriverCard", photoDriverCard);
            }
            myCarService.uploadFile(fd, function (data) {
                var fileArr = data.content;
                for(var i=0; i 

  照片的预览

 

 $scope.previewImage = function(fileId, imgId) {
            var preview = document.querySelector("#" + imgId);
            var file  = document.querySelector("#" + fileId).files[0];
            var reader = new FileReader();
            reader.onloadend = function () {
                preview.src = reader.result;
            }
            if (file) {
                reader.readAsDataURL(file);
            } else {
                preview.src = "http://www.soscw.com/images/noimg.png";
            }
        };

  

angular +H5 上传图片 与预览图片

标签:identity   script   card   ng-model   sub   conf   default   button   dex   

原文地址:http://www.cnblogs.com/mamimi/p/7132074.html


评论


亲,登录后才可以留言!