My main AppModule
has recently grown significantly so I want to cut it into multiple smaller modules. As the first step, I took a number of login / registration components and placed them in LoginModule
. There is one problem, though. Components that I've placed in LoginModule
depends on another module that is declared and configured in the main AppModule
. This required module accepts a number of configuration parameters and of course, I'd like to have it configured in one single place.
As an example, let's take IonicModule
but this question is Angular2-generic.
My main AppModule
imports IonicModule
and LoginModule
as well as provides a number of parameters to the IonicModule
.
imports: [
IonicModule.forRoot(MyApp, {
mode: 'ios',
tabsPlacement: 'bottom'
}),
LoginModule
]
Because all components in LoginModule
depends on IonicModule
I need to import IonicModule
there as well. What should I do with configuration parameters, though? I'd like to avoid copy-pastying them from AppModule
.
Is imports: [IonicModule]
in this case enough? Or do I need to extract configuration parameters somewhere and inject them every time I refer IonicModule
?
All other modules that I will extract, will need to have IonicModule
imported as well.
@NgModule({
imports: [IonicModule],
declarations: [
(...)
],
entryComponents: [
(...)
],
providers: (...)
})
export class LoginModule {}
You could take a look at shared modules section here
Theoretically,you could set the common dependancy modules in one module , export from there and import that. That way you could still set the parameters in one place. However , I havent tried doing this with a module that takes the app component in forRoot.
Hope it helps