angularjs上传 和 <input type="file">与ng-model 的玩法
来源:互联网 发布:网络作品版权出售 编辑:程序博客网 时间:2024/06/06 11:36
转自: 出处 (上传)
转自: 出处 (input 和 ng-model如何联系)
其中定义 file 这个 ng 指令是核心内容
<body ng-controller="con"> <h3>项目信息</h3> <form> 文件 <input type="file" name="upload_file" file="upload_file"><br> <input type="button" ng-click="sub()" value="保存"> </form></body><script type="text/javascript"> angular.module("app",[]) # 构建 file 指令必须有 .directive('file', function () { return { scope: { file: '=' }, link: function (scope, el, attrs) { el.bind('change', function (event) { var file = event.target.files; scope.file = file ? file : undefined; scope.$apply(); }); } }; }) .controller("con",function($scope,$http){ $scope.sub = function(){ tmp_file = $scope.upload_file $http({ headers : { 'content-type': 'multipart/form-data', }, method: "POST", url: "yourUrl", data : tmp_file, # ransformRequest 函数是必须有 transformRequest: function (data, headersGetter) { var formData = new FormData(); angular.forEach(data, function (value, key) { formData.append(key, value); }); var headers = headersGetter(); delete headers['Content-Type']; return formData; }, }).then(function(response){ console.log(response); },function(response){ console.log(response); }); } })</script>
阅读全文
0 0
- angularjs上传 和 <input type="file">与ng-model 的玩法
- angularJs 取<input type='file'>中文件名 (ng-model获取不了)
- ng-model获取不了type=file值的解决办法
- angularJS <input type="file> 图片的base64编码
- angularjs input ng-model 双向绑定无效的问题
- 更改上传文件的样式<input type="file>
- html 实时显示input type=file 上传的图片
- jquery获取input type=file的选中上传文件名
- 使用input标签 type='file' 上传图片的问题
- 浏览选择上传文件的控件 input type=file
- 上传按钮<input type='file'/>的样式美化
- springMVC <input type="file" 的简单上传至服务器
- <input type="file" >判断上传的文件是zip和rar类型
- input type='file' 上传错误
- 上传附件<input type="file">规则
- 使用input type="file"上传文件
- input type=file 服务器端上传文件
- <input type="file"/> 文件上传
- ORACLE中用rownum分页并排序的SQL语句
- linux
- 高效退出循环线程
- myeclipse进入Myeclipse configuration center 如何关闭
- 机器学习(Machine Learning)&深度学习(Deep Learning)资料
- angularjs上传 和 <input type="file">与ng-model 的玩法
- CSU 1811 Tree Intersection 平衡树启发式合并
- 开启服务的方式:(3)混合式开启
- 频道管理的简单使用
- 数据库 4 种隔离级别
- 深度学习在推荐领域的应用 Lookalike Facebook node2vec 深度学习 推荐领域
- 机器学习算法—K-近邻(二)
- Servlet初始化和filter过滤器映射的问题
- css中首行缩进无效的问题