I tried this code with no success
$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);
});
I checked here :
https://docs.angularjs.org/api/ng/service/$http
and there :
https://www.w3.org/TR/XMLHttpRequest/#events
It is just that I would like to improve my code with a progress bar on a big json file download to the app.
By the way, I could not find a way to log the overall $http object's functions and supported events as it returns a promise object with few info.
Don't use onprogress
, use just progress
, same with other events. I prepare a plunkr to demonstrate:
$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);
});
Also, there was a bug that has been fixed in angular 1.5.5 as it can be seen from the CHANGELOG. Update to the 1.5.5 or higher and it will work.
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