angular ng-file-upload文件图片上传

资源地址 : https://github.com/danialfarid/ng-file-upload

<script src="angular(.min).js"></script>
<script src="ng-file-upload-shim(.min).js"></script> <!-- for no html5 browsers support -->
<script src="ng-file-upload(.min).js"></script>

js代码

//注入 ngFileUpload (注意:如果你用ui-load对于每个html加载文件 ,要把ng-file-upload文件放到首页去加载,不能写在ui-load里面,以免注入的时候找不到文件)
var app = angular.module('fileUpload', ['ngFileUpload']);
//Upload
app.controller('MyCtrl', ['$scope', 'Upload', function ($scope, Upload) {


// 上传方法 uploadFiles
$scope.uploadFiles = function(file, errFiles) {
   
    var  url = '/product/pictures/updataPicture.do'; //接口名
     
    $scope.f = file;
    $scope.errFile = errFiles && errFiles[0];
    if (file) {
        file.upload = Upload.upload({
            url: url,
            data: {uploadFileName: file, 'prodId': $scope.prodId, 'prictureGroup': $scope.prictureGroup ,'sortOrder' : $scope.sortOrder}//参数对应
        });

        file.upload.then(function (res) {
            // 上传成功时操作
        }, function (response) {
            // if (response.status > 0)
            //     $scope.errorMsg = response.status + ': ' + response.data;
        }, function (evt) {
            // file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
        });
    }
};

  }]);

html代码

<button type="file" ngf-select="uploadFiles($file, $invalidFiles)" accept="mage/jpeg,image/gif,image/png" ngf-max-height="1000" ngf-max-size="1MB"></button> 
<img src="{{上传成功后接口返回图片url}}" alt="">
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值