Now Angular 1.5.4 finally allows you to track progress event on $http provider but for some reason I keep getting the $rootScope as a response instead of an actual progress (I'm using it for uploads) information. Because of lack of examples I found some tests in the Angular repo and followed that but to no success.
restClientInstance.post = function (requestParams) {
var postParams = {
method: "POST",
url: API_URL + requestParams.url,
headers: requestParams.headers,
data: requestParams.data,
eventHandlers: {
progress: function (c) {
console.log(c);
}
},
uploadEventHandlers: {
progress: function (e) {
console.log(e);
}
}
};
var promise = $http(postParams)
$rootScope.$apply();
return promise;
};
In both cases it consoles $rootScope rather than the lengthComputable
In AngularJS v1.5.7 works fine. If you have the chance I recommend upgrade!
...//formData = new FormData(); etc...
var postParams = {
method: 'POST',
url: yourURLWS,
transformRequest: angular.identity,
uploadEventHandlers: {
progress: function (e) {
if (e.lengthComputable) {
$scope.progressBar = (e.loaded / e.total) * 100;
$scope.progressCounter = $scope.progressBar;
}
}
},
data: formData,
headers: {'Content-Type': undefined }
};
var sendPost = $http(postParams); //etc...
in HTML you have:
<progress id="progress" max="100" value="{{progressBar}}"></progress>{{progressCounter}}%
Result:
progress result
The feature is broken for now: https://github.com/angular/angular.js/issues/14436
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With