Angularjs 如何在脱机时使用http侦听器
我正在用ionic构建一个应用程序,并在每个加载的请求上显示一个加载指示器。当请求完成时,加载指示器被移除。当存在网络连接时,这非常有效 脱机时,请求开始并显示加载指示器。问题是加载指示器永远不会消失,因为请求永远不会完成。我怎样才能最好地处理这件事?我在想暂停一下什么的。最好的方法是在用户脱机时根本不启动请求Angularjs 如何在脱机时使用http侦听器,angularjs,angular-http-interceptors,Angularjs,Angular Http Interceptors,我正在用ionic构建一个应用程序,并在每个加载的请求上显示一个加载指示器。当请求完成时,加载指示器被移除。当存在网络连接时,这非常有效 脱机时,请求开始并显示加载指示器。问题是加载指示器永远不会消失,因为请求永远不会完成。我怎样才能最好地处理这件事?我在想暂停一下什么的。最好的方法是在用户脱机时根本不启动请求 $httpProvider.interceptors.push(function($rootScope) { return { request: function(c
$httpProvider.interceptors.push(function($rootScope) {
return {
request: function(config) {
config.timeout = 5000;
$rootScope.$broadcast('loading:show')
return config
},
response: function(response) {
$rootScope.$broadcast('loading:hide')
return response
}
}
})
加在下面
responseError: function(response) {
$rootScope.$broadcast('loading:hide')
return response
}
requestError: function(response) {
$rootScope.$broadcast('loading:hide')
return response
}
您还应该尝试处理requestError和responseError。太棒了,我不知道这些事件!