@@ -1031,7 +1031,7 @@ function $HttpProvider() {
10311031</file>
10321032</example>
10331033 */
1034- function $http ( requestConfig ) {
1034+ function $http ( requestConfig , invokeApply ) {
10351035
10361036 if ( ! isObject ( requestConfig ) ) {
10371037 throw minErr ( '$http' ) ( 'badreq' , 'Http request configuration must be an object. Received: {0}' , requestConfig ) ;
@@ -1155,7 +1155,7 @@ function $HttpProvider() {
11551155 }
11561156
11571157 // send request
1158- return sendReq ( config , reqData ) . then ( transformResponse , transformResponse ) ;
1158+ return sendReq ( config , reqData , invokeApply ) . then ( transformResponse , transformResponse ) ;
11591159 }
11601160
11611161 function transformResponse ( response ) {
@@ -1318,7 +1318,7 @@ function $HttpProvider() {
13181318
13191319 function createShortMethods ( names ) {
13201320 forEach ( arguments , function ( name ) {
1321- $http [ name ] = function ( url , config ) {
1321+ $http [ name ] = function ( url , config , invokeApply ) {
13221322 return $http ( extend ( { } , config || { } , {
13231323 method : name ,
13241324 url : url
@@ -1330,7 +1330,7 @@ function $HttpProvider() {
13301330
13311331 function createShortMethodsWithData ( name ) {
13321332 forEach ( arguments , function ( name ) {
1333- $http [ name ] = function ( url , data , config ) {
1333+ $http [ name ] = function ( url , data , config , invokeApply ) {
13341334 return $http ( extend ( { } , config || { } , {
13351335 method : name ,
13361336 url : url ,
@@ -1347,7 +1347,7 @@ function $HttpProvider() {
13471347 * !!! ACCESSES CLOSURE VARS:
13481348 * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
13491349 */
1350- function sendReq ( config , reqData ) {
1350+ function sendReq ( config , reqData , invokeApply ) {
13511351 var deferred = $q . defer ( ) ,
13521352 promise = deferred . promise ,
13531353 cache ,
@@ -1465,11 +1465,16 @@ function $HttpProvider() {
14651465 resolvePromise ( response , status , headersString , statusText , xhrStatus ) ;
14661466 }
14671467
1468- if ( useApplyAsync ) {
1469- $rootScope . $applyAsync ( resolveHttpPromise ) ;
1468+ var skipApply = ( isDefined ( invokeApply ) && ! invokeApply ) ;
1469+ if ( ! skipApply ) {
1470+ if ( useApplyAsync ) {
1471+ $rootScope . $applyAsync ( resolveHttpPromise ) ;
1472+ } else {
1473+ resolveHttpPromise ( ) ;
1474+ if ( ! $rootScope . $$phase ) $rootScope . $apply ( ) ;
1475+ }
14701476 } else {
14711477 resolveHttpPromise ( ) ;
1472- if ( ! $rootScope . $$phase ) $rootScope . $apply ( ) ;
14731478 }
14741479 }
14751480
0 commit comments