angular-http-interceptor
Version:
A interceptor module to http calls
35 lines (34 loc) • 1.42 kB
JavaScript
import { NgModule, InjectionToken } from '@angular/core';
import { Http, XHRBackend, RequestOptions } from '@angular/http';
import { Interceptor } from './interfaces';
import { CustomHttp } from './custom-http';
export var INTERCEPTORS = new InjectionToken('Interceptor');
var InterceptorModule = /** @class */ (function () {
function InterceptorModule() {
}
InterceptorModule.withInterceptors = function (interceptorTypes) {
return {
ngModule: InterceptorModule,
providers: [
interceptorTypes,
{ provide: Http, useFactory: httpFactory, deps: [INTERCEPTORS, XHRBackend, RequestOptions] },
{ provide: CustomHttp, useExisting: Http },
]
};
};
InterceptorModule.decorators = [
{ type: NgModule, args: [{
providers: [
{
provide: Http, useFactory: httpFactory, deps: [Interceptor, XHRBackend, RequestOptions]
},
{ provide: CustomHttp, useExisting: Http }
]
},] },
];
return InterceptorModule;
}());
export { InterceptorModule };
export function httpFactory(httpInterceptors, connectionBackend, requestOptions) {
return new CustomHttp(httpInterceptors, connectionBackend, requestOptions);
}