我的应用程序是80%写在角度和20%的jQuery中。我已经使用$ httpprovider以角度编写了一个请求拦截器,并且与其他角页面一起工作良好。 我有三个问题:从jquery页面调用角度请求拦截器
1)我想为我的jquery页面使用相同的拦截器。我怎样才能做到这一点?
2)我希望我的拦截器只能在页面加载时调用一次。我怎样才能做到这一点?它目前被调用7-8次(我猜在完成页面加载期间调用ajax的次数)。
3)有人可以给我输入我怎么可以为这个拦截器和使用这个拦截器的页面编写jasmine spec。 在此先感谢!
app.config(['$httpProvider', function ($httpProvider) {
'use strict';
$httpProvider.interceptors.push('myAppInterceptor');
}]);
app.factory('myAppInterceptor', ['$q','$window','$injector',function ($q,$window,$injector) {
'use strict';
var myAppInterceptor = {
request: function(config) {
console.log('myAppInterceptor is called');
// some business logic done here...
}
return config;
}
};
return myAppInterceptor;
}]);
感谢您的回复。它有帮助。 –