分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

angularjs上传图片和文件

发布时间:2023-09-06 01:13责任编辑:傅花花关键词:js上传图片

很简单:

$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上传图片和文件

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved