我已经在Angular 7中创建了CoreModule
核心模块包含AccountService
和HttpInterceptor
服务:
providers: [..., AccountService,
{
provide: HTTP_INTERCEPTORS,
useClass: TokenInterceptor,
multi: true
}]
这是AccountService的代码:
constructor(private http: HttpClient,
@Inject('BASE_URL') public baseUrl: string,
private router: Router,
private notifierSrv: NotifierService) {
...
console.log('new acc srv');
...
}
AccountService被注入到HttpInterceptor服务:
@Injectable()
export class TokenInterceptor implements HttpInterceptor {
constructor(private accountSrv: AccountService) {
console.log(`TokenInterceptor init with acc: ${accountSrv}`);
}
...
主要AppModule
导入CoreModule
问题:在应用的首次加载期间,我在浏览器控制台(Chrome)中看到约300项服务创建 Browser Console Log
也有例外:
account.service.ts:43 RangeError: Maximum call stack size exceeded
注入器应将其创建为单例。我想念什么?