简体   繁体   English

Angular 2共享模块循环依赖

[英]Angular 2 shared module circular dependency

I have a share module that looks like this: 我有一个共享模块,如下所示:

@NgModule({
  exports: [
    CommonModule,
    HttpModule,
    OneModule,
    TwoModule
  ]
})
export class SharedModule {
}

The OneModule imports the SharedModule because he needs access to the other shared modules. OneModule导入SharedModule,因为他需要访问其他共享模块。

@NgModule({
  imports: [SharedModule],
  declarations: [SomeComponent]
})
export class OneModule {

}

When I console log the SharedModule I get undefined because I have circular dependency. 当我控制台登录SharedModule时,由于我具有循环依赖关系,因此无法定义。 How can I solve this? 我该如何解决?

Your SharedModule imports OneModule which imports SharedModule which imports OneModule and so on. 您的SharedModule导入OneModule ,后者导入SharedModule ,后者又导入OneModule ,依此类推。

To avoid this, you should try to make SharedModule have a SharedService that you can include in all your components, try to regroup the 'logical thinking' of your code in services. 为避免这种情况,您应该尝试使SharedModule具有可包含在所有组件中的SharedService ,并尝试重新组合服务中代码的“逻辑思维”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM