[英]ngResource custom headers when calling action
In ngResource action I can specify custom request headers. 在ngResource操作中,我可以指定自定义请求标头。 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). 原因是我需要为列表查询分页和排序数据,而这些数据需要由自定义标头(X-Order,X-Offset等)指定。 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)
(除了设置$ http默认值)
Try Restangular service. 尝试Restangular服务。
You can find there method: setFullRequestInterceptor which may fit your needs 您可以在其中找到方法: setFullRequestInterceptor ,它可以满足您的需求
//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 示例: http : //plnkr.co/edit/d6yDka?p = preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.