@@ -801,8 +801,12 @@ function $HttpProvider() {
801
801
* - **headers** – `{Object}` – Map of strings or functions which return strings representing
802
802
* HTTP headers to send to the server. If the return value of a function is null, the
803
803
* 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.
806
810
* - **xsrfHeaderName** – `{string}` – Name of HTTP header to populate with the XSRF token.
807
811
* - **xsrfCookieName** – `{string}` – Name of cookie containing the XSRF token.
808
812
* - **transformRequest** –
@@ -1261,11 +1265,31 @@ function $HttpProvider() {
1261
1265
}
1262
1266
1263
1267
$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 ) ) ;
1265
1271
}
1266
1272
1267
1273
return promise ;
1268
1274
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
+
1269
1293
1270
1294
/**
1271
1295
* Callback registered to $httpBackend():
0 commit comments