Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8ed3035

Browse files
committed
feat($http): add notify callback
Allows progress notifications for $http requests. This makes use of the readyState 3 of XMLHttpRequest.
1 parent 729c238 commit 8ed3035

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/ng/http.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ function $HttpProvider() {
991991
}
992992

993993
$httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
994-
config.withCredentials, config.responseType);
994+
config.withCredentials, config.responseType, notify);
995995
}
996996

997997
return promise;
@@ -1026,6 +1026,14 @@ function $HttpProvider() {
10261026
}
10271027

10281028

1029+
/**
1030+
* Notify callback registered to $httpBackend()
1031+
*/
1032+
function notify(xhr) {
1033+
deferred.notify(xhr);
1034+
}
1035+
1036+
10291037
/**
10301038
* Resolves the raw $http promise.
10311039
*/

src/ng/httpBackend.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
4040
var ABORTED = -1;
4141

4242
// TODO(vojta): fix the signature
43-
return function(method, url, post, callback, headers, timeout, withCredentials, responseType) {
43+
return function(method, url, post, callback, headers, timeout, withCredentials, responseType, notify) {
4444
var status;
4545
$browser.$$incOutstandingRequestCount();
4646
url = url || $browser.url();
@@ -103,6 +103,8 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
103103
response,
104104
responseHeaders,
105105
statusText);
106+
} else if (xhr && xhr.readyState == 3 && notify) {
107+
notify(xhr);
106108
}
107109
};
108110

0 commit comments

Comments
 (0)