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

I use ng2-bootstrap and import ModalModule.forRoot() to do modal use. I follow the Angular style guide as far as I know how to do this. I need to use modals in other places in my application than before, and I'm trying to move the import to a more global module. The problem is that Angular usually does not allow me to export it from my general module or my main module, because it uses forRoot() . Following the best practices, I understand that I should not import it into my AppModule ; they say that AppModule more stable if it is kept minimally and is used only for importing CoreModule and for downloading the application. So where to import it?

+5
source share
1 answer

When using ModalModule.forRoot (), it registers material that is needed only once in the application database. (Appmodule)

Then you can import ModalModule to any place you need it and will use singleton objects created with .foorRoot ().

So, in your case, you should use ModalModule.foorRoot () in the AppModule, then in your general module you must first imports: [ModalModule] , and then exports: [ModalModule] so that it is available everywhere.

Ps. There is a more complete bootstrap project by the same guys who made ui-bootstrap for angular 1: https://ng-bootstrap.imtqy.com

+2
source

Source: https://habr.com/ru/post/1263465/


All Articles