angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

Add invokeApply option to $http

Open offsky opened this issue 13 years ago • 19 comments

$timeout has the 'invokeApply' option that allows you to skip dirty checking. It would be very handy to have this option on $http as well.

Why: My application has a periodic $http request to look for updates on the server. 99% of the time there are no updates. It would be more efficient if angular could not run through the entire apply() loop in these cases, which can cause performance issues if the page has lots of bindings. I am getting around this right now by using jquery ajax and calling apply() myself, but I would prefer to use angular's $http.

offsky avatar Feb 21 '13 19:02 offsky

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

btford avatar Aug 24 '13 00:08 btford

I still think that adding an invokeApply option to $http would be valuable.

offsky avatar Oct 02 '13 21:10 offsky

Makes sense to me. $timeout and $http seem to be somewhat similar in that they both kick off an async operation. Since $timeout offers the possibility to not call $rootScope.$apply automatically it would make sense in terms of symmetry to have that option on $http as well.

cburgdorf avatar Oct 02 '13 23:10 cburgdorf

This should be a pretty low impact change, would it open for a pull request?

We could simply add a new option invokeApply that matches the naming of $timeout, and simply skips the $scope.$apply() call in the done() callback. This would also need to be added to $resource for the the action options object.

david-driscoll avatar Nov 18 '13 16:11 david-driscoll

+1

uglow avatar Dec 24 '13 00:12 uglow

this is not so simple. http is fundamentally based on promises and angular's promises are made asynchronous via $digest queue, so making an $http call that doesn't cause $digest would require the http promise to use some other async queue mechanism (e.g. setTimeout, or something better).

I doubt that this will happen in 1.3 as it is a pretty big change.

IgorMinar avatar Jan 08 '14 08:01 IgorMinar

+1

konsultaner avatar Feb 12 '14 12:02 konsultaner

+1 - would be a great feature to leverage in logging frameworks, etc

booleanbetrayal avatar Jul 21 '14 21:07 booleanbetrayal

+1 Other frameworks such as rxjs will trigger (or not) different async calls depending on success or error. Having an option to disabling auto-apply would help in implementing such callbacks consistently.

Javarome avatar Aug 04 '14 09:08 Javarome

@caitp : Now that we have $$q wouldn't it be easier to add this feature ?

gkalpak avatar Oct 14 '14 10:10 gkalpak

Sure

caitp avatar Oct 14 '14 12:10 caitp

+1 from me, I consider it a very useful feature. There are scenarios when you have many isolated business components/directives on the page that make many $http calls, some of those request promises get aggregated, developer needs to be in control of promise callbacks triggering $scope.$apply() and maybe do it only once at the very last promise resolution.

okonovalenko avatar Jan 02 '15 00:01 okonovalenko

+1 from me as well.

strille avatar May 01 '15 09:05 strille

I'm having some success by directly calling $httpBackend. At least it means you don't have to include another library like jQuery.

philBrown avatar Sep 07 '15 02:09 philBrown

See https://github.com/angular/angular.js/pull/12557

Narretz avatar Sep 14 '15 10:09 Narretz

This would be an awesome feature for large applications that use multiple pooling ajax calls. Big +1.

@IgorMinar : we may let the user debounce several ajax calls and have him manually trigger the $digest via $evalAsync/$timeout --- it's the whole point of avoiding the $apply no?

Can we get this merged soon?

dragosrususv avatar Mar 07 '16 19:03 dragosrususv

I agree, this is not just for polling, it's relevant for many http requests scenarios. There are already pull requests so what's keeping it outside of the master?

onemenny avatar Mar 24 '16 16:03 onemenny

I need this, too....

ronnieoverby avatar Mar 29 '16 17:03 ronnieoverby

+1

As a side question: @dragosrususv why should we avoid $apply? It seems circuitous to do a $evalAsync/$timeout when you can just do it directly.

poshest avatar Oct 27 '16 11:10 poshest