redhead
redhead

Reputation: 1317

ngResource custom headers when calling action

In ngResource action I can specify custom request headers. However I need to set the headers at the time of calling the resource action.

The reason is I need paging and sorting data for the list query, and those need to be specified by custom headers (X-Order, X-Offset, and so on). This data can vary from call to call, so I cannot have them in the resource action definition.

Is there a way to pass headers while calling the action? (other than setting $http defaults)

Upvotes: 0

Views: 155

Answers (1)

Teq1
Teq1

Reputation: 631

Try Restangular service.

You can find there method: setFullRequestInterceptor which may fit your needs

//From Documentation
RestangularProvider.setFullRequestInterceptor(function(element, operation, route, url, headers, params, httpConfig) {
      return {
        element: element,
        params: _.extend(params, {single: true}),
        headers: headers,
        httpConfig: httpConfig
      };
    });

Examples: http://plnkr.co/edit/d6yDka?p=preview

Upvotes: 1

Related Questions