I got provider in app.module defined as follows:
{
multi: true,
deps: [ServiceA, ServiceB],
provide: HTTP_INTERCEPTORS,
useClass: HttpResponseInterceptor,
}
And it works fine. Problem is, I need ServiceB to be configurable by factory function and also serviceB is optional but something like this doesn't work:
// Factory function
serviceBFactory = (param) => { // returns instance of my service or null, depends on param }
...
deps: [ ServiceA, { provide: ServiceB, useFactory: serviceBFactory } ]
...
Error I get:
Error: StaticInjectorError(AppModule)[InjectionToken HTTP_INTERCEPTORS -> [object Object]]:
StaticInjectorError(Platform: core)[InjectionToken HTTP_INTERCEPTORS -> [object Object]]
NullInjectorError: No provider for [object Object]!
Is there any special syntax for it or it's not possible by design?