Note. I have not tried this approach yet, but have been playing with the idea because we are looking at a similar problem.
, URL/, . , angular API . .
HttpClient API/, . , angular HttpClient :
providers: [
HttpClient,
{
provide: HttpHandler,
useFactory: interceptingHandler,
deps: [HttpBackend, [new Optional(), new Inject(HTTP_INTERCEPTORS)]],
},
interceptingHandler ɵinterceptingHandler. , , , .
Anyawy, HttpClients :
export const MY_HTTP_INTERCEPTORS = new InjectionToken<HttpInterceptor[]>('MY_HTTP_INTERCEPTORS');
...
providers: [
MyHttpClient,
{
provide: MyHttpHandler,
useFactory: interceptingHandler,
deps: [HttpBackend, [new Optional(), new Inject(MY_HTTP_INTERCEPTORS)]],
},
, MyHttpClient MyHttpHandler .