Angular Circular Module Dependencies

I have the following circular module dependency problem:

Accepted angular modules:

  • DatabaseMenuModule - search and view a database table
  • DetailViewModule (child of a database module) - View one dataset in a table
  • SubtableModule - clicking on a foreign key opens another instance of DatabaseMenu in a modal dialog enter image description here

The general structure is a kind of recursion that involves recursion, since each dataset can have foreign keys and therefore open (on click) another instance of the database menu. As shown in the picture, I have a circular import of modules and therefore it doesn't work.

zone.js:917 Uncaught Error: Unexpected value 'undefined' imported by the module 'SubtableModule'

      

But I also see no way to resolve this circle.

Does anyone have a flaw on how to solve this problem?

+3


source to share


1 answer


You need to get rid of the circular reference.

Your SharedModule will import OneModule, which will import SharedModule, which will import OneModule, etc.

To avoid this, you should try to force the SharedModule to have a SharedService that you can include in all of your components, try to regroup the "logical thinking" of your code in services.



If you want to use a component for multiple modules, you need to create a "shared" module and add that component to export the shared module. Then you add this common module to your other modules.

An example is here: https://thinkster.io/tutorials/angular-2-ngmodule/creating-the-sharedmodule

0


source







All Articles