【发布时间】:2019-09-19 06:32:07
【问题描述】:
很简单,我有一个 AuthenticationService 和一个 UserService。 UserService 包含在 AuthenticationService 中。然后当我在 UserService 中使用 AuthenticationService 时:
constructor(private authService: AuthenticationService){}
我明白了:
Circular dependency detected:
src/app/core/authentication/authentication.service.ts -> src/app/shared/services/user.service.ts -> src/app/core/authentication/authentication.service.ts
这两个服务都在应用模块提供者数组中声明。为什么会出现循环依赖?
【问题讨论】:
-
因为正如你所说,你在
UserService和UserService中注入了AuthenticationServiceAuthenticationService -
Angular 不知道先创建哪个。
标签: angular typescript circular-dependency