I have a directive that reacts to an Blur event fired from an input element, and then ultimately results in a call to the Angular $http service to make an appropriate HTTP request.
The $http service is being called correctly and generating the expected promise, however the actual HTTP request does not get made immediately. It is only triggered later after making other kinds of DOM interactions.
Why are the request not being made immediately? And how can I force them to be made immediately?
Angular v1.1.5
I eventually found the answer in the issues on GitHub (https://github.com/angular/angular.js/issues/2442):
v1.1.4... changed the way $http worked so that it was scheduled on nextTick instead of firing immediately. This means that if your $http is scheduled from something that doesn't cause a $digest to fire then your request won't be sent. You can verify that this is the behavior you're seeing by clicking on the page a few times (anywhere) and you should see your request go out.
As the post suggested I triggered a $digest cycle, which caused my $http generated requests to be immediately fired.
scope.$apply();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With