html中
<div class="picture col-lg-4 col-md-4 col-sm-4 col-xs-12"> <div class="picture-box"> <img class="picture-box-img" ng-src="{{vm.data.gsPic}}" alt=""/> </div> <button class="button1" ng-click="uploadImg();vm.imgType = 2">上传</button> </div>
在下边还有这么一个button 位置在上传图片的下边,最好跟上传图片的div在一级。
<button style="display:none;" ng-model='filename' ng-change="fileUploaded(data)" upload='"/ajax/1.0/article/article/img/1"' accpet=".jpg,.png,.jpeg"></button>
angular js中
$scope.uploadImg=function(){ $('button input[type="file"]').click(); }; $scope.fileUploaded = function(data) { if(vm.imgType == 1){ vm.data.businessPic = data.url; }else if(vm.imgType == 2){ vm.data.gsPic = data.url; }else if(vm.imgType == 3){ vm.data.otherPic = data.url; } };