Angular onreadystatechange
Angular newbie here. I was wondering if the $ http service could be used to call a function on any state / state, not just success / failure. In terms of code, it will be the equivalent angular code for the following JS code :
var xhr = new XMLHttpRequest();
xhr.onreadystatechange=function() {
if (xhr.readyState < 4 && xhr.status != 200)
alert('Loading');
}
xhr.open...
xhr.send...
+3
source to share
2 answers
This event is no longer used in 1.3+ and is not displayed and only uses state 4 in 1.2.
The only way to do something like this (if you really wanted to) is to replace or decorate $ httpBackend ...
See createHttpBackend()
at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular.js
+1
source to share
Another option that I've used successfully is calling $ scope. $ apply () after what would otherwise be a call to $ http:
// using $http
var promise = $http.get(url).then(success, ...);
// without $http
$.ajax({
url: url,
success: function() {
success();
$scope.$apply(); // if you'd used $http, this would be unnecessary
},
...
});
0
source to share