Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Add invokeApply option to $http #2049

Open
offsky opened this issue Feb 21, 2013 · 19 comments
Open

Add invokeApply option to $http #2049

offsky opened this issue Feb 21, 2013 · 19 comments

Comments

@offsky
Copy link

offsky commented Feb 21, 2013

$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.

@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

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!

@offsky
Copy link
Author

offsky commented Oct 2, 2013

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

@cburgdorf
Copy link
Contributor

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.

@btford btford reopened this Oct 3, 2013
@david-driscoll
Copy link

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.

@uglow
Copy link

uglow commented Dec 24, 2013

+1

@IgorMinar
Copy link
Contributor

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.

@konsultaner
Copy link

+1

@booleanbetrayal
Copy link
Contributor

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

@Javarome
Copy link

Javarome commented Aug 4, 2014

+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.

@gkalpak
Copy link
Member

gkalpak commented Oct 14, 2014

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

@caitp
Copy link
Contributor

caitp commented Oct 14, 2014

Sure

@okonovalenko
Copy link

+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.

@strille
Copy link

strille commented May 1, 2015

+1 from me as well.

@philBrown
Copy link
Contributor

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

@Narretz
Copy link
Contributor

Narretz commented Sep 14, 2015

See #12557

@dragosrususv
Copy link

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?

@onemenny
Copy link

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?

@ronnieoverby
Copy link

I need this, too....

@poshest
Copy link
Contributor

poshest commented Oct 27, 2016

+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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests