ashfaq.p ashfaq.p - 7 days ago 6
Javascript Question

Do i need to add a plugin to every module in angular 2?

I am using

ng-bootstrap
with angular 2. I have it imported in my
app.module
and it's working fine.

I am lazy-loading another module and
ng-bootstrap
components are not working in that. They work if I import ng-bootstrap module again in the lazy-loaded module.

My question is: Do I need to import 3-rd party modules again in every module I write or there is some way of making them to work by some setting ?

PS: I am a newbie to angular 2

Answer
You have to import a module in whatever module you want to use components, directives or pipes of the imported module. There is no way around it.

What you can do is to create a module that exports several other modules (like for example the `BrowserModule` that exports `CommonModule`.

@NgModule({
  declarations: [CoolComponent, CoolDirective, CoolPipe],
  imports: [MySharedModule1, MySharedModule2],
  exports: [MySharedModule1, MySharedModule2, CoolComponent, CoolDirective, CoolPipe],
})
export class AllInOneModule {}

@NgModule({
  imports: [AllInOneModule]
})
class MyModule {}

This way you make everything exported by AllInOneModule available to MyModule.

Comments