【发布时间】:2019-04-10 07:40:41
【问题描述】:
所以我找到了几十篇解释这个问题的文章,大多数建议都说将我的组件添加到 @NgModule 中的 entryComponents 数组中,但我对我拥有的许多模块中的哪个或哪些 entryComponents 感到困惑.. 所以基本上我的模块依赖项如下所示:
AppModule
- EnvironmentModule
- ContainerModule
- SharedModule
EnvironmentModule
- ContainerModule
- EnvironmentListItemDetailComponent
private _dialogRef: MatDialogRef<ConfirmDialogComponent>;
ContainerModule
- MatDialogModule,
- ConfirmDialogComponent (this is the component that I want to move)
- ContainerListItemDetailComponent
private _dialogRef: MatDialogRef<ConfirmDialogComponent>;
基本上,我想将 ConfirmDialogComponent 从嵌套子模块移动到环境和容器模块都可以依赖的共享模块。 (我也很想将 ContainerModule 从 EnvironmentModule 下移出,但那是另一天的事了)
所以我想把 ConfirmDialogComponent 移到 SharedModule 中,然后把所有东西都连接起来,App、Environment、Container、Shared 的 @NgModule 是什么样的?我真的很困惑..所以这是我到目前为止所拥有的:
shared.module.ts:
@NgModule({
imports: [
CommonModule,
MatDialogModule,
BrowserAnimationsModule
],
declarations: [
ConfirmDialogComponent
],
exports: [
ConfirmDialogComponent
],
entryComponents: [
ConfirmDialogComponent
]
})
export class SharedModule { }
environment.module.ts:
@NgModule({
imports: [
HttpClientModule,
CommonModule,
FormsModule,
EnvironmentRoutingModule,
ContainerModule
],
declarations: [
EnvironmentListComponent,
EnvironmentListEnvironmentsComponent,
EnvironmentListItemDetailComponent,
EnvironmentListItemComponent
],
providers: [... ]
})
container.module.ts:
@NgModule({
imports: [
FormsModule,
CommonModule,
BrowserAnimationsModule,
MatDialogModule,
ContainerRoutingModule
],
declarations: [
KeysPipe,
ContainerListComponent,
ContainerListItemComponent,
ContainerListItemDetailComponent,
ParameterListComponent,
ParameterListItemComponent,
ParameterTypeInfoComponent,
ConfirmDialogComponent
],
exports: [
ContainerListComponent
],
providers: [...],
entryComponents: [ ConfirmDialogComponent ]
})
app.module.ts:
@NgModule({
declarations: [
AppComponent
],
imports: [
FormsModule,
BrowserModule,
AppRoutingModule,
HttpModule,
ContainerModule,
EnvironmentModule,
LoginModule,
SharedModule,
PageNotFoundModule /* DO NOT MOVE THIS - as a result of routing peculiarities the order of child routes matter for handling wildcard ** https://stackoverflow.com/questions/40015385/angular-2-router-wildcard-handling-with-child-routes */
],
providers: [
AppConfigService,
AuthGuardService,
BootstrapService,
EventBrokerService,
HttpClientService,
TruIdTokenService,
StartupService,
{
provide: APP_INITIALIZER,
useFactory: initConfiguration,
deps: [StartupService],
multi: true
}
],
bootstrap: [AppComponent]
})
所以我不知道:\ 这有点乱,我什至不确定我的所有依赖项是否组织正确。
【问题讨论】:
-
只需从您的子模块中删除入口组件(ConfirmDialogComponent),例如 ContainerModule 和 EnvironmentModule ,我认为它会起作用
标签: angular angular-components angular-module angular-cli-v6