From 8ed3035be044144c040b10018ee4cef800c04bd9 Mon Sep 17 00:00:00 2001 From: Chris Chua Date: Wed, 24 Sep 2014 12:56:50 -0700 Subject: [PATCH] feat($http): add notify callback Allows progress notifications for $http requests. This makes use of the readyState 3 of XMLHttpRequest. --- src/ng/http.js | 10 +++++++++- src/ng/httpBackend.js | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ng/http.js b/src/ng/http.js index e10207c57f99..f244f8adc49c 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -991,7 +991,7 @@ function $HttpProvider() { } $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout, - config.withCredentials, config.responseType); + config.withCredentials, config.responseType, notify); } return promise; @@ -1026,6 +1026,14 @@ function $HttpProvider() { } + /** + * Notify callback registered to $httpBackend() + */ + function notify(xhr) { + deferred.notify(xhr); + } + + /** * Resolves the raw $http promise. */ diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 78d04cfa24b9..3fdc3d298c4b 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -40,7 +40,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc var ABORTED = -1; // TODO(vojta): fix the signature - return function(method, url, post, callback, headers, timeout, withCredentials, responseType) { + return function(method, url, post, callback, headers, timeout, withCredentials, responseType, notify) { var status; $browser.$$incOutstandingRequestCount(); url = url || $browser.url(); @@ -103,6 +103,8 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc response, responseHeaders, statusText); + } else if (xhr && xhr.readyState == 3 && notify) { + notify(xhr); } };