如何使用带有angularjs 1 http请求的eventHandlers和uploadEvntHandlers?

Man*_*sse 8 http xmlhttprequest angularjs

我试过这段代码没有成功

$http({
    method:"GET",
    url:"data/mycooljsonfile.json",
    eventHandlers:{
        onprogress:function(event){
        console.log("progress");
        console.log(event);
    },onreadystatechange:function(event){
        console.log("change");
        console.log(event);
    }
    },
    uploadEventHandlers:{
         onprogress:function(object){
              console.log(object);
         }
    }
})
.success(function(json){ // succès
     $scope.lemmes=json;
      //console.log($http);
}).error(function(error){ // erreur
    console.log(error);
});
Run Code Online (Sandbox Code Playgroud)

我查了一下:

https://docs.angularjs.org/api/ng/service/ $ http

那里:

https://www.w3.org/TR/XMLHttpRequest/#events

只是我希望通过大型json文件下载到应用程序的进度条来改进我的代码.

顺便说一句,我找不到一种方法来记录整个$ http对象的函数和支持的事件,因为它返回一个信息很少的promise对象.

gan*_*rty 8

不要使用onprogress,使用progress,与其他事件一样.我准备一个plunkr来证明:

  $http({
      method: "GET",
      url: "data.json",
      eventHandlers: {
        progress: function(event) {
          console.log("progress");
          console.log(event);
        },
        readystatechange: function(event) {
          console.log("change");
          console.log(event);
        }
      },
      uploadEventHandlers: {
        progress: function(object) {
          console.log(object);
        }
      }
    })
    .success(function(json) { // succès
      $scope.lemmes = json;
      //console.log($http);
    }).error(function(error) { // erreur
      console.log(error);
    });
Run Code Online (Sandbox Code Playgroud)

此外,还有一个错误已在角度1.5.5中修复,因为从CHANGELOG可以看到.更新到1.5.5或更高版本,它将工作.