1

I have an issue figuring out how I can pass a component from a module I import into my Angular application and use it inside another module that I import also in my App.

Note that all those two modules are modules I created.

That's my app.module.ts :

@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    PnDashboardComponent,
    PnFormulaireComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    LayoutModule.forRoot(environment.layout),
    DispoModule.forRoot(environment.dispoAides)
  ],
  providers: [
    ErrorsHandler,
    InitialisationService,
    InitializationGuard
  ],
  bootstrap: [AppComponent]
})

What I want to do is pass a component let's say called BreadcrumbComponent from the LayoutModule to the DispoModule and beeing able to use it inside that module.

Note that LayoutModule and DispoModule are dependent angular module project that are packaged with ng-packagr and imported in my Application.

Thank you.

Imad El Hitti
  • 917
  • 3
  • 10
  • 23

2 Answers2

1

You need to create a SharedModule and declare the BreadcrumbComponent in it. Also export the component so that i can be used across other Modules.

Import the SharedModule wherever you want to use BreadcrumbComponent in the application

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • I edited the question, I forgot to mention that the modules are dependent projects that where packaged and imported in my app, so I think your solution doesn't work in that situation – Imad El Hitti Sep 26 '18 at 09:52
1

If you want to do is pass a component let's say called BreadcrumbComponent from the LayoutModule to the DispoModule and beeing able to use it inside that module.

then write

exports: [
    BreadcrumbComponent
]

in your LayoutModule

and import LayoutModule in DispoModule

Amrit
  • 2,115
  • 1
  • 21
  • 41
  • I can't import LayoutModule in DispoModule because I don't want to put the LayoutModule in the package.json of the DispoModule. I don't see the point of installing the whole package if I want only one component of it. – Imad El Hitti Sep 26 '18 at 12:20