AngularJS页面传参的5种方式(3)

(function() { 'use strict'; angular .module('myApp') .factory('authInterceptorService', authInterceptorService); /** @ngInject */ function authInterceptorService($q, $injector, $location) { var authService = $injector.get('authService'); var authInterceptorServices = { request: request, responseError: responseError }; return authInterceptorServices; //////////////// // 将token注入所有HTTP requests的headers。 function request(config) { var authParams = authService.getAuthenticationParams(); config.headers = config.headers || {}; if (authParams.authtoken) config.headers.authtoken = authParams.authtoken; return config || $q.when(config); } function responseError(rejection) { if (rejection.status === 401) { authService.logout(); $location.path('/login'); } return $q.reject(rejection); } } })();

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwydsd.html