diff --git a/src/ng/http.js b/src/ng/http.js index fbdc89a50cf0..1f77546ca428 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -905,7 +905,7 @@ function $HttpProvider() { // if we won't have the response in cache, send the request to the backend if (!cachedResp) { $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout, - config.withCredentials, config.responseType); + config.withCredentials, config.responseType, config.hooks); } return promise; diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index ed8404f96cfb..4ffa76403932 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -32,7 +32,7 @@ function $HttpBackendProvider() { function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, locationProtocol) { // 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, hooks) { var status; $browser.$$incOutstandingRequestCount(); url = url || $browser.url(); @@ -59,9 +59,21 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, if (value) xhr.setRequestHeader(key, value); }); + // Add listeners for events such as progress + hooks = hooks || {}; + var uploadHooks = hooks.upload || {}; + delete hooks.upload; + forEach(Object.keys(hooks), function(event) { + xhr.addEventListener(event, hooks[event], false); + }); + forEach(Object.keys(uploadHooks), function(event) { + xhr.upload.addEventListener(event, uploadHooks[event], false); + }); + // In IE6 and 7, this might be called synchronously when xhr.send below is called and the // response is in the cache. the promise api will ensure that to the app code the api is // always async + xhr.onreadystatechange = function() { if (xhr.readyState == 4) { var responseHeaders = xhr.getAllResponseHeaders();