Modules with circular dependency with Angular 4

663 views
Skip to first unread message

Arnaud Deman

unread,
Nov 2, 2017, 8:42:07 AM11/2/17
to Angular and AngularJS discussion
Hello,

Is it possible with  angular 4 to define two angular modules that depend each other ?

A use case could be, for instance, a Group Module and a User Module.
The Group module would depend upon the User module to display the members of groups in its template and the User would depend the Group to display the memberships of users.
Both would need to add the other one in the import section of its NgModule metadata.

I am trying to do something similar and it fails at compilation with AOT : RangeError: Maximum call stack size exceeded. When I use JIT compilation it fails at runtime with this error :
Error: (SystemJS) Unexpected value 'undefined' imported by the module 'StructureModule'. 

Thanks for your help,
Regards,
Arnaud.


Sander Elias

unread,
Nov 2, 2017, 11:18:48 AM11/2/17
to Angular and AngularJS discussion
Hi Arnaud.

I don't think that is possible. What you can do is extract the functionality that you need in both into a 3rth module that you include in both.
Or the other way around, that you create a module a level ábive'the ones you have now, and pull in both.

Regards
Sander

Arnaud Deman

unread,
Nov 2, 2017, 11:34:31 AM11/2/17
to Angular and AngularJS discussion
Hi Sander,

Thanks for your answer.
That was what I feared. As the two modules use each other rather than sharing functionalities I will have to create a new module to group both as you said.

Regards,
Arnaud.
Reply all
Reply to author
Forward
0 new messages