Simplified version of the code:
@Injectable()
export class JwtInterceptor implements HttpInterceptor {
constructor(
private readonly router: Router,
private readonly activatedRouteSnapshot: ActivatedRouteSnapshot,
@Inject(AuthServiceFactory) private readonly authServiceFactory: ServiceFactoryBase<IAuthService>,
@Inject(LoggingServiceFactory) private readonly loggingServiceFactory: ServiceFactoryBase<ILoggingService>) {
console.log('router', router);
console.log('activated-route-snapshot', activatedRouteSnapshot);
}
None of that can be resolved. It fails with a standard message saying following:
StaticInjectorError(AppModule)[InjectionToken HTTP_INTERCEPTORS -> ActivatedRouteSnapshot]: StaticInjectorError(Platform: core)[InjectionToken HTTP_INTERCEPTORS -> ActivatedRouteSnapshot]: NullInjectorError: No provider for ActivatedRouteSnapshot!
..what is the correct way to import RouterModule
into an application?
P.S. I got SharedModule
rather than the AppModule
to export all mine stuff but not Angular's:
@NgModule({
declarations: any.concat(pipes),
providers: any
.concat(serviceFactories)
.concat(guards)
.concat(otherProviders)
.concat([{
provide: HTTP_INTERCEPTORS,
useClass: JwtInterceptor,
multi: true
}]),
exports: any.concat(pipes)
})
export class SharedModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: SharedModule,
providers: any
.concat(serviceFactories)
.concat(guards)
.concat(otherProviders)
};
}
}
The the AppModule
:
@NgModule({
declarations: appComponents.concat(auxComponents),
imports: [
// theirs
BrowserModule,
HttpClientModule,
AppRoutingModule,
// ours
SharedModule,
CoursesModule
],
bootstrap: [
AppComponent
]
})
export class AppModule { }