Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to import (export?) a module using forRoot?

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?

like image 870
BBaysinger Avatar asked Jan 27 '17 18:01

BBaysinger


1 Answers

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

like image 91
Leon Radley Avatar answered Oct 26 '22 23:10

Leon Radley