【发布时间】:2017-09-14 23:36:43
【问题描述】:
是否可以让拦截器在向服务器发送请求之前等待某个事件?
拦截器的代码如下:
(function() {
"use strict";
angular.module("fuse").config(config);
/** @ngInject */
function config($httpProvider, $provide) {
$provide.factory("httpInterceptor", function($q, $rootScope) {
return {
request: function(config) {
// I need to wait for some event, read its argument and add this argument to the headers
return config || $q.when(config); // Only return after handling the event
},
response: function(response) {
console.log("Data Count: " + response.data.length);
return response || $q.when(response);
}
};
});
$httpProvider.interceptors.push("httpInterceptor");
}
})();
如您所见,在返回配置对象之前,我想处理一些包含我需要添加到标头的附加数据的事件。
有可能吗?
【问题讨论】:
标签: angularjs angular-http-interceptors