My application is 80% written in angular and 20% in jquery. I have written a request interceptor in angular using $httpprovider and it is working fine with other angular pages. I have three questions:
1) I want to use the same interceptor for my jquery page. How may I achieve this?
2) I want my interceptor to be called only once at page load. How may I achieve this ? It is presently getting called 7-8 times (I guess the number of ajax calls during the complete page load).
3) Can someone give me inputs how may I write jasmine spec for this interceptor and for the pages using this interceptor. Thanks in advance!
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;
}]);