我构建了一个具有根模块的应用程序,然后在此模块下有3个子模块。在模块1中,有一个组件可以在模块3中重复使用,但是,如果我直接访问模块3中的组件URL,组件将永远不会加载(我认为发生这种情况是因为模块1未加载)。我已经尝试过的部件从模块1导出和根模块引导它,但我得到一个错误,指出组件选择没有被发现Angular 2组件不在不同模块中加载
---编辑---
根模块
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
ManagerModule,
LogadoModule,
GeralModule,
RouterModule.forRoot(routes, {useHash: true})
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
模块1
@NgModule({
declarations: [
GeralComponent,
GeralHeaderComponent,
LoginComponent,
AtividadesListagemComponent // -> COMPONENT TO BE SHARED
],
imports: [
CommonModule,
ReactiveFormsModule,
FormsModule,
GeralRoutingModule
],
providers: [GeralService],
exports: [GeralComponent],
bootstrap: [GeralComponent]
})
export class GeralModule{}
模块3 // - >在该模块中使用共享组件
@NgModule({
declarations: [
LogadoComponent,
AtividadesInscritoComponent,
LogadoHeaderComponent
],
imports: [
CommonModule,
ReactiveFormsModule,
FormsModule,
LogadoRoutingModule
],
providers: [],
exports: [LogadoComponent],
bootstrap: [LogadoComponent]
})
export class LogadoModule{}
这个项目的结构:
根模块 模块1 模块2 模块3
----编辑2 -----
共享模块
@NgModule({
imports: [CommonModule],
exports : [
CommonModule,
AtividadesListagemComponent
],
declarations: [AtividadesListagemComponent]
})
export class SharedModule { }
根模块
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
ManagerModule,
LogadoModule,
GeralModule,
RouterModule.forRoot(routes, {useHash: true})
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
模块1
@NgModule({
declarations: [
GeralComponent,
GeralHeaderComponent,
LoginComponent
],
imports: [
CommonModule,
ReactiveFormsModule,
FormsModule,
GeralRoutingModule,
SharedModule
],
providers: [GeralService],
exports: [GeralComponent],
bootstrap: [GeralComponent]
})
export class GeralModule{}
模块3
@NgModule({
declarations: [
LogadoComponent,
AtividadesInscritoComponent,
LogadoHeaderComponent
],
imports: [
CommonModule,
ReactiveFormsModule,
FormsModule,
LogadoRoutingModule,
SharedModule
],
providers: [],
exports: [LogadoComponent],
bootstrap: [LogadoComponent]
})
export class LogadoModule{}
请提供一些代码,以便我们可以查看。 – DeborahK
@DeborahK完成:) – julianomontini