diff --git a/src/ng/http.js b/src/ng/http.js index 4ca89e4fd3d1..d9a5cd6a1b30 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -977,7 +977,7 @@ function $HttpProvider() { // if we won't have the response in cache, send the request to the backend if (isUndefined(cachedResp)) { $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout, - config.withCredentials, config.responseType); + config.withCredentials, config.responseType, notify); } return promise; @@ -1004,6 +1004,16 @@ function $HttpProvider() { } + /** + * Callback registered to $httpBackend(): + * - propagates xhr events via notify + * - calls $apply + */ + function notify(event) { + deferred.notify(event); + if (!$rootScope.$$phase) $rootScope.$apply(); + } + /** * Resolves the raw $http promise. */ diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index f52e461157f0..5f32e5b6f1df 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -36,7 +36,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, notifyCallback) { var status; $browser.$$incOutstandingRequestCount(); url = url || $browser.url(); @@ -97,6 +97,10 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc } }; + xhr.upload.onprogress = function(e) { + notifyCallback(e); + }; + if (withCredentials) { xhr.withCredentials = true; } diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index c2c9d7a2be97..af8deb0470d6 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -1653,6 +1653,8 @@ function MockXhr() { return lines.join('\n'); }; + this.upload = {}; + this.abort = angular.noop; } diff --git a/test/ng/httpBackendSpec.js b/test/ng/httpBackendSpec.js index 2a3f60126737..4967b0e4fac1 100644 --- a/test/ng/httpBackendSpec.js +++ b/test/ng/httpBackendSpec.js @@ -245,6 +245,8 @@ describe('$httpBackend', function() { }; this.getAllResponseHeaders = valueFn(''); + + this.upload = {}; } callback.andCallFake(function(status, response) {