jsFiddle Example: Proper Timeout Handling with AngularJS
- July 23, 2014 11:00 AM
- AngularJS, Examples & Tutorials, Javascript
- Comments (3)
AngularJS has a really poor handling of timeouts, at least for complex HTTP calls. You can provide a timeout in milliseconds, but if the request does time out, you just get a cancelled request. Now this might be fine for simple situations, but when you have CORS Ajax calls, you end up not being able to tell a timeout from a CORS request failure (at least not easily). This can be handled by switching to setting the timeout with a Promise instead. This code shows how to use a promise for your timeout in AngularJS to get clear error messages.