Within my codebase, there exists the following constructor:
constructor(env: Env, private logger: Logger,
@Inject(MockEndpoints.TOKEN) @Optional()
private endpoints: MockEndpoints[]) {
// ...
}
It functions as intended when utilized with the JIT compiler. However, when the AOT compiler is enabled, it triggers a build error:
ERROR in : Can't resolve all parameters for MockBackendInterceptor in /path/mock-backend.interceptor.ts: ([object Object], [object Object], ?).
The structure of the token object is outlined below:
export interface MockEndpoints {
handle(req: HttpRequest<any>): HttpResponse<any>;
}
export namespace MockEndpoints {
export const TOKEN: InjectionToken<MockEndpoints[]> =
new InjectionToken<MockEndpoints[]>('MockEndpoints');
}
I was under the impression that I followed the documentation guidelines precisely. Any suggestions or insights? ;)
UPDATE (in response to Gunter's comment): The endpoints are registered within the same module:
@NgModule({
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: MockBackendInterceptor, multi: true },
{ provide: MockEndpoints.TOKEN, useClass: MockBackupService, multi: true },
{ provide: MockEndpoints.TOKEN, useClass: MockConfigurationService, multi: true }
]
})
export class MockBackendModule { }