I'm using ng2-bootstrap
, and importing ModalModule.forRoot()
to accomplish modal usage. I'm following the Angular style guide as best I know how. I have a need to use modals in more places in my app than I did before, and I'm trying to move the import out to a more global module. The problem is that Angular wont just let me export it from my shared module or my core module because it uses forRoot()
. Following best practices, I understand that I shouldn't import it in my AppModule
; they say AppModule
is more stable if it's kept minimal and is only used for importing CoreModule and bootstrapping the application. So where do I import it?
When using ModalModule.forRoot() it registers stuff that is only need once at the base of the app. (AppModule)
You can then import ModalModule any where you need it, and it will use the singleton objects created by .foorRoot().
So in your case you should use ModalModule.foorRoot() in the AppModule
then in your shared module you should first imports: [ModalModule]
, and then exports: [ModalModule]
so that it's available everywhere.
Ps. There is a more complete bootstrap project by the same guys who did ui-bootstrap for angular 1 called: https://ng-bootstrap.github.io
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With