How read the URL and parameter from HTTP interceptor $httpProvider in angular js

孤者浪人 提交于 2019-12-02 10:33:28

After few searching i have found the answer. You have to write a filter and inject that to http

$httpProvider.interceptors.push('myHttpInterceptor');

Please find the full code

angular.module("app").config(['$httpProvider', function ($httpProvider) {
        if (!$httpProvider.defaults.headers.get) {
            $httpProvider.defaults.headers.get = {};
            $httpProvider.interceptors.push('myHttpInterceptor');
        }
        else {
        }
        $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
        $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
        $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
    }
]);

angular.module('app').factory('myHttpInterceptor', function ($q) {
    return {
        // optional method
        'request': function (config) {
            debugger;
            return config;
        },
        // optional method
        'requestError': function (rejection) {
            // do something on error
            return $q.reject(rejection);
        },
        // optional method
        'response': function (response) {
            // do something on success
            return response;
        },
        // optional method
        'responseError': function (rejection) {
            // do something on error
            return $q.reject(rejection);
        }
    };
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!