#Multiples instances of forRoot in modules

5 messages · Page 1 of 1 (latest)

tacit fulcrum
#

From angular Begginer:

I work today on a monolith.
I have a shared components folder and the module that imports the dependencies has an import:
"TourMatMenuModule.forRoot()".

I have to leave this import with "forRoot()" because of a component that would break if it didn't have it.

Elsewhere I need to use this module with forRoot as well, but they start to conflict.

Is there any way I can check if there is already an instance of this module in the application and from there render with forRoot or not?

In this case, I would put this conditional rendering in the shared components module.

Other solutions are welcome as well.

pure nacelle
#

forRoot() is (conventionally) for the root module only. Everywhere else, you shouldn't use it.

steel dew
#

I have to leave this import with "forRoot()" because of a component that would break if it didn't have it.

#
  • Put the TourMatMenuModule.forRoot call in the AppModule
  • Import TourMatMenuModule without .forRoot() in your shared components NgModule
tacit fulcrum