码迷,mamicode.com
首页 > Web开发 > 详细

angularjs上传图片和文件

时间:2017-09-23 17:13:07      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:smo   style   iss   hang   cti   code   mob   bsp   col   

很简单:

$scope.upload = function() {
			var f = $scope.myFile;
			var fd = new FormData();
			var img = document.querySelector(‘input[type=file]‘).files[0];
			//var file = [];
			//file.push(f);
			// file.push(img);
			fd.append(‘issueId‘, ‘1‘);
			fd.append(‘file‘, img);
			$http.post(‘/images‘, fd, {
				transformRequest: angular.identity,
				headers: {
					‘Content-Type‘: undefined
				}
			}).success(function (response) {
				debugger;
			}).error(function(response) {
				debugger;
			});
		};

  html

<div class="container" style="boeder: 1px solid #ddd">
                            <input type="file" name="pic" id="pic" emms-file-upload="myFile">
                            <a class="btn btn-primary" ng-click="upload()">upload</a>
                        </div>

directives: 可用可不用

    emmsMobile.directive(emmsFileUpload, function() {
        return {
            restrict: ACE,
            link: function(scope, elem, attr) {
                elem.on(change, function() {
                    scope.file = this.files[0];
                })
            },
            scope: {
                file: =emmsFileUpload
            }
        }
    })

 

angularjs上传图片和文件

标签:smo   style   iss   hang   cti   code   mob   bsp   col   

原文地址:http://www.cnblogs.com/nelson-hu/p/7581605.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!