我目前正在使用角度指令上传文件...
var fd = new FormData();
fd.append("uploadedFile", scope.uploadedFile);
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListenter("load", uploadComplete, false);
xhr.addEventListenter("error", uploadFailed, false);
xhr.addEventListenter("abort", uploadCanceled, false);
xhr.open("POST", scope.postUrl);
scope.uploadInProgress = true;
xhr.send(fd);
function uploadProgress(e){
scope.$apply(function(){
if(e.lengthComputable){
scope.progress = Math.round(e.loaded * 100 / e.total);
} else {
scope.progress = 'unable to compute';
}
});
}
...
可以使用 $http 提供程序重构此代码段吗?我不知道如何保留我的事件监听器。