是否有可能在角所有的HTTP调用之前检查的条件? [英] Is it possible to check condition before all http calls in Angular?
本文介绍了是否有可能在角所有的HTTP调用之前检查的条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能检查: $ rootScope.variable为TRUE
所有 $ HTTP
通话被称为前,还是应该检查每个单独拨?一些我的电话都是通过角调用工厂
,而有些则不是。
Before all $http
calls are called, or I should check for every individual call? Some of my calls are call through angular factory
, and some are not.
我觉得有可能是一些喜欢httpInterceptor方式有些呼叫前跑这将检查。
I thought there is maybe some way like httpInterceptor which would check before some call is ran.
任何帮助将AP preciated。
Any help would appreciated.
推荐答案
您可以创建一个的拦截了解这个问题像这样的:
You can create an interceptor for this issue like this one:
angular.module('myModule', []).config(function($httpProvider) {
$httpProvider.interceptors.push(function($rootScope) {
return {
'request': function(config) {
if($rootScope.yourVariable) {
// cancel this request
}
}
}
});
})
This interceptor processes every request. You can find an implementation for cancelling requests here
这篇关于是否有可能在角所有的HTTP调用之前检查的条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文