@@ -801,8 +801,12 @@ function $HttpProvider() {
801801 * - **headers** – `{Object}` – Map of strings or functions which return strings representing
802802 * HTTP headers to send to the server. If the return value of a function is null, the
803803 * header will not be sent. Functions accept a config object as an argument.
804- * - **events** - `{Object}` - Event listeners to be bound to the XMLHttpRequest object.
805- * To bind events to the XMLHttpRequest upload object, nest it under the upload key.
804+ * - **eventHandlers** - `{Object}` - Event listeners to be bound to the XMLHttpRequest object.
805+ * To bind events to the XMLHttpRequest upload object, use `uploadEventHandlers`.
806+ * The handler will be called in the context of a `$apply` block.
807+ * - **uploadEventHandlers** - `{Object}` - Event listeners to be bound to the XMLHttpRequest upload
808+ * object. To bind events to the XMLHttpRequest object, use `eventHandlers`.
809+ * The handler will be called in the context of a `$apply` block.
806810 * - **xsrfHeaderName** – `{string}` – Name of HTTP header to populate with the XSRF token.
807811 * - **xsrfCookieName** – `{string}` – Name of cookie containing the XSRF token.
808812 * - **transformRequest** –
@@ -1261,11 +1265,31 @@ function $HttpProvider() {
12611265 }
12621266
12631267 $httpBackend ( config . method , url , reqData , done , reqHeaders , config . timeout ,
1264- config . withCredentials , config . responseType , config . events ) ;
1268+ config . withCredentials , config . responseType ,
1269+ createApplyHandlers ( config . eventHandlers ) ,
1270+ createApplyHandlers ( config . uploadEventHandlers ) ) ;
12651271 }
12661272
12671273 return promise ;
12681274
1275+ function createApplyHandlers ( eventHandlers ) {
1276+ if ( eventHandlers ) {
1277+ var applyHandlers = { } ;
1278+ forEach ( eventHandlers , function ( eventHandler , key ) {
1279+ applyHandlers [ key ] = function ( ) {
1280+ if ( useApplyAsync ) {
1281+ $rootScope . $applyAsync ( eventHandler ) ;
1282+ } else if ( $rootScope . $$phase ) {
1283+ eventHandler ( ) ;
1284+ } else {
1285+ $rootScope . $apply ( eventHandler ) ;
1286+ }
1287+ } ;
1288+ } ) ;
1289+ return applyHandlers ;
1290+ }
1291+ }
1292+
12691293
12701294 /**
12711295 * Callback registered to $httpBackend():
0 commit comments