一尘不染

如何在带有$ http或$ resource的angularjs 1.5.5中使用eventHandlers和uploadEventHandlers跟踪进度?

angularjs

我试图严格遵守使用$ http或$ resource进行文件上传的angularjs代码。

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);
});

这些事件根本没有触发。我想念什么?

参考资料

  1. https://github.com/angular/angular.js/issues/14436
  2. https://github.com/angular/angular.js/pull/11547

阅读 156

收藏
2020-07-04

共1个答案

一尘不染

发布查询后找到它。感觉很蠢。我必须在bower中更新angularjs版本,以确保所有依赖项都解析为angular 1.5.5及更高版本。

详细信息参考

2020-07-04