有人可以帮助我吗?
x.factory("inter", ["$q", function($q) {
return {
request: function(config) {
console.log("Request: " + JSON.stringify(config));
return config;
}
};
}]);
x.config(["$httpProvider", function($httpProvider) {
$httpProvider.interceptors.push("inter");
}]);
谢谢!
答案 0 :(得分:2)
用
替换您的代码x.factory("inter", ["$q", function($q) {
var configs = [];
return {
request: function(config) {
configs.push("Request: " + JSON.stringify(config));
return config;
},
interceptedConfigs: configs
};
}]);
x.config(["$httpProvider", function($httpProvider) {
$httpProvider.interceptors.push("inter");
}
然后,在控制器中控制你想要打印配置的视图,注入拦截器,并将其配置暴露在范围内:
x.controller('SomeCtrl', function($scope, inter) {
$scope.interceptedConfigs = inter.interceptedConfigs;
});
然后在该控制器的视图中:
{{ interceptedConfigs }}