在转换请求函数中获取$http选项
Get $http options in transorm request function
我在AngularJS应用程序中有一个请求转换函数。根据传递给$http的参数,我需要在请求发送之前执行不同的操作。但似乎请求转换函数只获得数据作为输入。有没有一种方法可以在Angular中完成它,并且只使用标准的$http ?
使用请求拦截器:
app.config(['$httpProvider', function($httpProvider){
var myHttpInterceptor = ['$rootScope', '$q', function($rootScope, $q){
return {
'request': function(config) {
// config is an object you passed to $http(config);
// you are free to modify config or return a new one
if(config./*your logic*/){
// I want to perform an action depending on $http options. But I want to do it before request is performed
// + you can return $q.reject('reason') if you want to stop this http request with rejetion
// + you can return a promise that resolves with config object. http request will continue when this promise resolves or is rejected
}
return config || $q.when(config);
}
};
}];
$httpProvider.interceptors.push(myHttpInterceptor);
}]);
更多信息搜索拦截器段落https://docs.angularjs.org/api/ng/service/$http
相关文章:
- 我的单元测试选项是什么
- 如何更改bigquery API中的计费层选项
- 使用Javascript获取所选选项ID
- Selectize.js:如何对整数值的选项进行排序
- 通过js在新选项卡中有条件地打开url
- 按照选项卡索引的顺序循环一个jQuery选择
- Meteor如何接收HTTP请求
- 如何在使用selectBoxIt JQuery插件时检测选项更改
- 无法在Ionic select中预先选择最后一个选项
- 如何在选项卡上定义属性'的主窗口对象
- 浏览器不发送 CORS HTTP 选项用于发布请求
- $http发布呼叫选项而不是发布
- 打开一个新选项卡以在 AngularJS 中发出 http 请求
- 将curl选项传递给node-js-http请求
- web扩展选项页面的HTTP请求不工作
- 如何从选项中获取angularjs的http请求url
- 如何在ng-options中添加一个硬编码选择选项,该选项由$http.get填充
- 当$http service返回选项列表时,Ng-option不工作
- 在转换请求函数中获取$http选项
- 如何确定Firefox浏览器中的哪个选项卡将发出http请求