Angular 2必须使用@Inject(forwardRef(…)才能注入服务

Angular 2必须使用@Inject(forwardRef(…)才能注入服务,angular,angular2-services,angular2-injection,Angular,Angular2 Services,Angular2 Injection,我的应用程序中有一项服务存在问题。问题是,无论在何处注入此服务,我都会遇到以下错误: Uncaught (in promise): Error: Can't resolve all parameters for TestComponent: ([object Object], ?, [object Object]) 我知道这个问题可能是由于使用桶造成的,但是我不是将桶用于服务,而是“直接”引用文件,例如:。/../core/services/config.service 正如本文所建议的,我尝

我的应用程序中有一项服务存在问题。问题是,无论在何处注入此服务,我都会遇到以下错误:

Uncaught (in promise): Error: Can't resolve all parameters for TestComponent: ([object Object], ?, [object Object])
我知道这个问题可能是由于使用桶造成的,但是我不是将桶用于服务,而是“直接”引用文件,例如:
。/../core/services/config.service

正如本文所建议的,我尝试在任何注入此服务的地方使用
@Inject(forwardRef(…)
)。我唯一的例外是
AppComponent
,在这种情况下,我“正常”注入相同的服务,并且没有得到错误:

export class AppComponent implements OnInit {
    constructor(
        private configService: ConfigService, // NO ERROR
        private router: Router
    ) { }

    ...

}
在所有其他地方,如果不执行以下操作,则会出现上述错误:

export class BuyButtonComponent {
    constructor(
        @Inject(forwardRef(() => ConfigService)) private configService: ConfigService,
        // private configService: ConfigService // DOES NOT WORK
    ) { }

    ...

}
我的理解是,
forwardRef()
在要注入依赖项但尚未定义时使用。
ConfigService
由导入到
AppModule
中的
CoreModule
提供。组件要么在我拥有的
SharedModule
FeatureModule

不确定是否有人能够解释为什么此特定服务需要在任何组件中使用
forwardRef
(除了
AppComponent
),而以相同方式导入和提供的所有其他服务都以“正常方式”注入

更新

以下是提供服务的方式:

核心模块

应用模块


ConfigService
是从
CoreModule
提供的,没有其他地方。此外,
CoreModule
仅在
AppModule
中导入。其想法是从单个模块提供服务。该服务正在其他模块中声明的组件中使用(
SharedModule
FeatureModule

forwardRef
主要用于需要使用仅在同一文件中进一步声明的标识符时。错误消息表明未提供某些依赖项,或者存在循环依赖项。您很可能具有循环依赖项。。您正在导入提供程序中的组件吗?例如,
buybutoncomponent
是否在任何提供商中导入?TestComponent的构造函数是什么样子的?感谢您的回复,我已经用如何提供服务的示例更新了这个问题。我不提供任何组件中的任何服务。它可能是一个循环依赖,但如果是这样,我不知道它可能在哪里。
TestComponent
有一个构造函数,它注入了另外两个服务和
ConfigService
构造函数(private-shoppingListService:shoppingListService,private-ConfigService:ConfigService,private-userService:userService){}
阅读以了解我们为什么需要
forwardRef
。这可能不是你的情况
@NgModule({
    providers: [
        // Other Services...
        ConfigService
    ]
})
export class CoreModule { }
@NgModule({
    bootstrap: [AppComponent],
    imports: [
        BrowserModule,
        FormsModule,
        HttpModule,
        BrowserAnimationsModule,
        CoreModule,
        AppRoutingModule
    ]
})
export class AppModule { }