angularjs – requestError http拦截器的用例

前端之家收集整理的这篇文章主要介绍了angularjs – requestError http拦截器的用例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
根据 http://docs.angularjs.org/api/ng.$http,拦截器有以下方法

request: function(config) {
  //we could manipulate query here
  return config || $q.when(config);
},requestError: function(rejection) {
  // what is the use case of this?
  return $q.reject(rejection);
},response: function(response) {
  // response.status === 200
  return response || $q.when(response);
},responseError: function(rejection) {
  // when response Failed ...
  return $q.reject(rejection);
}

requestError是如何触发的,你能想到什么用例?

解决方法

一个有趣的用例是拆除/撤消在请求之前设置的内容,并且在响应之后会被拆除.例子:

>装载指标
>叠加
>禁用表单字段

现在,当请求无法发送或被另一个拦截器拒绝时,requestError使您有机会正确操作并删除该加载指示符或启用表单字段.

猜你在找的Angularjs相关文章