发表于: 2016-12-31 01:01:35
0 1347
2. 明天的计划:
争取完成task7,学习angular的表单事件的用法.
3. 遇到的困难:
1 . nginx的跨域配置,里面只填写请求的地址,具体的接口写在异步请求的url里面.
2.获取file的对象;用于请求的数据,和图片预览的功能
<form ng-app='app' ng-controller='upload'>
<input type="file" onchange='angular.element(this).scope().fileChanged(this)' />
<button ng-click='upload()'>upload</button>
<li>{{files[0].name}}</li>
<img ng-src={{files[0].name}} />
</form>
var app = angular.module('app',[]);
app.controller('upload',function($scope){
$scope.fileChanged = function(ele){
$scope.files = ele.files;
$scope.$apply();
}
$scope.upload = function(){
console.log($scope.files);
}
});
3. 图片缩略图的预览
window.URL.createObjectURL(files);传入获取到的file对象就能得到上传上来的本地图片,这样写很粗暴,而且这是h5的新方法,兼容性不好,
https://developer.mozilla.org/zh-CN/docs/Using_files_from_web_applications
4.图片提交一直404...暂时找不到原因
4. 今天的收获:
以上
评论