如何使用 $http 或 $resource 在 angularjs 1.5.5 中使用 eventHandlers 和 uploadEventHandlers 跟踪进度? [英] How to track progress using eventHandlers and uploadEventHandlers in angularjs 1.5.5 with $http or $resource?
本文介绍了如何使用 $http 或 $resource 在 angularjs 1.5.5 中使用 eventHandlers 和 uploadEventHandlers 跟踪进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图严格遵守 angularjs 代码,使用 $http 或 $resource 进行文件上传.
I am trying to strictly adhere to angularjs code using $http or $resource to do file upload.
var uploadData = new FormData();
uploadData.append('file', obj.lfFile);
var fileData = angular.toJson({
'FileName': obj.lfFile.name,
'FileSize': obj.lfFile.size
});
uploadData.append('fileData', fileData)
$http({
method: 'POST',
url: vm.uploadPath,
headers: {
'Content-Type': undefined,
'UserID': vm.folder.UserID,
'ComputerID': vm.folder.ComputerID,
'KeepCopyInCloud': vm.keepCopyInCloud,
'OverWriteExistingFile': vm.overwriteExistingFile,
'RootFileID': vm.folder.RootFileID,
'FileName': obj.lfFile.name,
'FileSize': obj.lfFile.size
},
eventHandlers: {
progress: function(c) {
console.log('Progress -> ' + c);
console.log(c);
}
},
uploadEventHandlers: {
progress: function(e) {
console.log('UploadProgress -> ' + e);
console.log(e);
}
},
data: uploadData,
transformRequest: angular.identity
}).success(function(data) {
console.log(data);
}).error(function(data, status) {
console.log(data);
console.log(status);
});
事件根本没有被触发.我错过了什么?
The events are not fired at all . What am i missing ?
参考资料
推荐答案
发布查询后找到.感觉很傻.我必须在 bower 中更新 angularjs 版本,以确保所有依赖项都解析为 angular 1.5.5 及更高版本.
Found it after posting the query. Feeling stupid. I had to update the angularjs version in bower to ensure all dependencies resolve to angular 1.5.5 and above.
这篇关于如何使用 $http 或 $resource 在 angularjs 1.5.5 中使用 eventHandlers 和 uploadEventHandlers 跟踪进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文