如何在 AngularJs 中设置全局 http 超时 [英] How to set a global http timeout in AngularJs
本文介绍了如何在 AngularJs 中设置全局 http 超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我每次都可以设置超时时间:
I know I can set a timeout each and every time:
$http.get('path/to/service', {timeout: 5000});
...但我想设置一个全局超时以保持我的代码干燥.
... but I want to set a global timeout to keep my code DRY.
推荐答案
UPDATED: $http 将不尊重 httpProvider 中设置的超时的默认设置(请参阅评论).可能的解决方法:https://gist.github.com/adnan-i/5014277
UPDATED: $http will not respect default setting for timeout set it in httpProvider (see the comments). Possible workaround: https://gist.github.com/adnan-i/5014277
原答案:
angular.module('MyApp', [])
.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.timeout = 5000;
}]);
这篇关于如何在 AngularJs 中设置全局 http 超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文