chintogtokh chintogtokh - 1 month ago 9
AngularJS Question

Setting a default header for all requests in Angular except OPTIONS

Is there a way to include a default header in AngularJS for all requests except the Options request?

I know you could do this for patch, put, and post by (for example for post):


But for everything except Options?


You can use an http interceptor to add your header on each request

app.config(['$provide', '$httpProvider', function ($provide, $httpProvider) {
    $provide.factory('httpInterceptor', ['$rootScope', '$q', '$injector', function ($rootScope, $q, $injector) {
        return {
            // occurs on request
            request: function (config) {
                //Add your header to the request here
                return config;
    $httpProvider.config(['$httpProvider', function ($httpProvider) {