angular在1.5.5以上的版本中,在$http中也加入了eventHandler和uploadEventHandlers等方法。
发送请求:
$http({method:"POST",url:basePath+"/roadShow/saveOrUpdate",eventHandlers: {progress: function(c) {console.log('Progress -> ' + c);console.log(c);}},uploadEventHandlers: {progress: function(e) {console.log('UploadProgress -> ' + e);console.log(e.loaded/e.total*100);}},data:form,headers:{"Content-Type":undefined},transformRequest: angular.identity})
其中,可以用e.loaded/e.total*100来计算进度:
实际应用时,可结合Math.floor()。