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
note - I have not worked with NG 1.5.4, the example below is for leveraging existing pre 1.5.4 APIs
The
notify(event)
API is part of the deferred object when you call$q.defer()
. I'm not sure what a practical implementation of this would be in terms of a typical get/put/post call via$http
. But if you want to see it in action you can do something like this:some service API
using the notification
codepen - http://codepen.io/jusopi/pen/eZMjrK?editors=1010
Again, I must stress that I'm not entirely sure how you can tie this into an actual external http call.
Well I ended up doing something like this and just handle it myself as the XHR events added to $http dont work for me.
The feature is broken for now: https://github.com/angular/angular.js/issues/14436
As seen in the docs here, the third parameter in a promise is a
notify
function.It can be used like this:
In AngularJS v1.5.7 works fine. If you have the chance I recommend upgrade!
in HTML you have:
Result:
progress result