Angular 拦截器(403、401)
来源:互联网 发布:中文域名在线转码程序 编辑:程序博客网 时间:2024/05/23 01:57
直接上代码:
angular.module('webb-ui').factory('authInterceptor', ['$q','$rootScope','$location','$injector','$timeout',function ($q,$scope,$location,$injector,$timeout) { function isNotPriv(url){ return url.indexOf("/priv/") === -1 } var authInterceptor = { 'request': function(config) { var deferred = $q.defer(); var url = config.url; deferred.resolve(config); return deferred.promise; }, 'response':function(response){ return response; }, 'responseError': function(rejection) { var rootScope = $injector.get('$rootScope'); if(isNotPriv(rejection.config.url)){ var status = rejection.status; if(status === 403){ $scope.four_zero_th = true;//自己的业务逻辑处理代码 rootScope.selectEtl(); return rejection; }else if(status === 401) { $scope.four_zero_one = true; rootScope.selectEtl(); return rejection; } } return $q.reject(rejection); } }; return authInterceptor;}]);
说明:responseError 此例子主要是对请求异常进行统一的拦截处理。
angular.module('webb-ui').config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationProvider', function ($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { $httpProvider.interceptors.push('authInterceptor'); /* *这里删除一个$injector,解决不能获取code码的问题。 * */ //$httpProvider.interceptors.pop();}]);
0 0
- Angular 拦截器(403、401)
- Angular统一拦截器(httpInterceptor)
- Angular拦截器
- angular JS 拦截器总结
- Angular $http拦截器介绍与使用
- Angular $http拦截器介绍与使用
- Angular $http拦截器计算请求耗时
- Spring mvc拦截器+angular js拦截器 做用户登录拦截控制
- angular 路由拦截
- angular 拦截器每个请求传递用户的token
- 为Angular内置$http服务添加拦截器
- 【Angular】angular-HttpClient 与服务器通讯 Get Post Put Delete Http 拦截器 请求讲解
- Angular 4.3 HttpClient (Angular访问 REST Web 服务) 三、拦截器 Interceptors
- angular 未登录状态拦截路由跳转
- Interceptor登录拦截(Spring拦截器)
- 拦截器(Interceptor)
- 拦截器(自定义)
- Filter(拦截器)
- 博客笔记总结2
- Material Design (四) TabLayout的使用
- Docker基本介绍
- __toString方法
- JAVAWEB开发模式之JSP的几种开发模式、处理Cookie中文乱码
- Angular 拦截器(403、401)
- servlet 的乱码问题
- 玩转数据挖掘的第一阶段——入门篇
- python 代码自动加载的问题
- ES6和ES5特性对比
- 博客笔记总结1
- Material Design (五) CollapsingToolbarLayout的使用
- cmd批处理常用符号详解
- WebSocket连接wss链接