app.config(function(RestangularProvider) {
RestangularProvider.addRequestInterceptor(function(element) {
console.log("Request started");
return element;
});
RestangularProvider.addResponseInterceptor(function(data) {
console.log("Request returned");
return data;
});
});
我正在尝试弄清楚如何在请求进行时创建微调器。我怀疑这通常是通过在请求开始时显示 a 并在请求完成时隐藏它来完成的。
我如何使用 Angular 和 Restangular 做到这一点?我有上面的拦截器设置,但这是在 .conifg() 中,所以我无法访问 $rootScope 或任何东西来跟踪任何 div 的可见性。
最佳答案
事实证明,我可以在 run()
block 内部配置 Restangular,这样我就可以访问 $rootscope
:
app.run(function($rootScope, Restangular) {
Restangular.addRequestInterceptor(function(element) {
$rootScope.xhr = true;
return element;
});
Restangular.addResponseInterceptor(function(data) {
$rootScope.xhr = false;
return data;
});
});
关于javascript - 矩形微调器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24088610/