Search code examples
angularangular-componentsangular-module

Use component lazy loading in multi components angular?


I have Three components (NavbarComponent , IndexComponent , PoweredComponent ) so I use lazy loading I need use components in multi components ,I don't know how to declare the component for using it in the lazy module. I'll show you some of the relevant parts of the different files:

  1. NavbarComponent
    navbar.module.ts
  declarations: [NavbarComponent],
  imports: [
    CommonModule
  ],
  exports: [NavbarComponent]
})
  1. IndexComponent
    Index.module.ts
  declarations: [IndexComponent ,NavbarComponent],
  imports: [
    CommonModule,
    IndexRoutingModule,
  ],
})

index.component.html

<app-navbar></app-navbar>
<div>...</div>

in index show navbar

index.component.html

  1. PoweredComponent
    powered.module.ts
@NgModule({
  declarations: [PoweredComponent,NavbarComponent],
  imports: [
    CommonModule,
    PoweredRoutingModule,
  ], 
})

powered.component.html

<app-navbar></app-navbar>
<div>...</div>

in powered.component.html no show navbar

issue <app-navbar></app-navbar> not dispaly in multi components can show jsut in index components

Pleas help me???
Thank's to read!!!


Solution

  • Index.module.ts

      declarations: [IndexComponent],
      imports: [
        CommonModule,
        IndexRoutingModule,
        NavbarModule
      ],
    })
    

    powered.module.ts

    @NgModule({
      declarations: [PoweredComponent],
      imports: [
        CommonModule,
        PoweredRoutingModule,
        NavbarModule
      ], 
    })