You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Discovering and loading NgModule at runtime. #18053
It is not possible to load dynamicall NgModules that have not been compiled at the same time of the whole application.
Angular-cli and webpack currently requier all code and modules used by the application in order to best optimize the production files. It does split the application into chunks corresponding to dynamic NgModules, but chunks are closely linked together.
Expected behavior
There should be an Option in angular-cli/webpack that allow independancy and reuse of chunks it generates even though final result is less optimal regarding code size and optimization.
I believe, Dynamic Loading of NgModule has been designed with this idea in mind since it doesn't requier NgModules to be statically imported in the router. This idea seem to have been lost in the race for perfect optimization (which is great by the way).
What is the motivation / use case for changing the behavior?
Actual trend is to do MicroService that encapsulate complete buisness behaviour and interface. This allows to developp and upgrade part of large application without the need to re-compile and redeploy the wole lot. Angular should take this into account and allow NgModules exposed in different micro-serviceto be discovered and loader at run time.
Reacted by Andreas Stahl, Alexei, bp117, May Chan, Shawn Scott, Tair Sabirgaliev, Michael Martz, Riceball LEE, Gabriel Llamas, Andrei and 1 more
changed the title [-]Feature Request : Discovering and loading NgModule at runtime.[/-][+]Discovering and loading NgModule at runtime.[/+]on Jul 11, 2017
This is not CLI specific, and unfortunately there's nothing we will do. The CLI does not support building libraries or individual application parts (like "just" a NgModule).
I'll talk to @robwormald who's worked with similar setup in the past and we will answer this in the Angular repo (or elsewhere if it doesn't fit in either). Leaving this open in the meantime to keep the discussion around.
Any updates on this? This is a common scenario for Enterprise, and we're currently stuck on this as well. We would like to migrate from AngularJS, but this seems to be a show stopper.
@bmbell ... if you use original Angular libs (UMDs) ... you can share them (even using advantages of a browser cache) ... and you can compile NgModules independently just via ngc compiler (then using any bundler as you want) and load them programmatically (without router) on-demand right now. The only condition is just using the same Angular version and recompiling all app's parts in a moment when moving to a newer version.
@mlc-mlapis I would love to see an example of this in action, as the documentation on loading a module programatically is sparse. It also feels like I'm digging myself into a hole - isn't the underlying API considered private and subject to change?
@mlc-mlapis: Thanks! This makes a lot of sense when trying to dynamically load a component. However, this doesn't get me all the way to what I'm specifically looking to do. I might need to create a new item for that...I'm specifically trying to load a module that specifies routing information and would add this information to the routing table (under a specific parent route that I would need to specify).
Activity
[-]Feature Request : Discovering and loading NgModule at runtime.[/-][+]Discovering and loading NgModule at runtime.[/+]trotyl commentedon Jul 11, 2017
Possibly relates to #15510
chuckjaz commentedon Jul 24, 2017
This seems to me like a feature request for angular-cli.
pdelorme commentedon Aug 17, 2017
you are right.
I'm moving it to angular/angular-cli#7405
hansl commentedon Aug 22, 2017
This is not CLI specific, and unfortunately there's nothing we will do. The CLI does not support building libraries or individual application parts (like "just" a NgModule).
I'll talk to @robwormald who's worked with similar setup in the past and we will answer this in the Angular repo (or elsewhere if it doesn't fit in either). Leaving this open in the meantime to keep the discussion around.
bmbell commentedon Feb 13, 2018
Any updates on this? This is a common scenario for Enterprise, and we're currently stuck on this as well. We would like to migrate from AngularJS, but this seems to be a show stopper.
mlc-mlapis commentedon Feb 13, 2018
@bmbell ... if you use original Angular libs (UMDs) ... you can share them (even using advantages of a browser cache) ... and you can compile NgModules independently just via ngc compiler (then using any bundler as you want) and load them programmatically (without router) on-demand right now. The only condition is just using the same Angular version and recompiling all app's parts in a moment when moving to a newer version.
bmbell commentedon Feb 14, 2018
@mlc-mlapis I would love to see an example of this in action, as the documentation on loading a module programatically is sparse. It also feels like I'm digging myself into a hole - isn't the underlying API considered private and subject to change?
mlc-mlapis commentedon Feb 15, 2018
@bmbell ... it could be something like:
where
and
bmbell commentedon Feb 15, 2018
@mlc-mlapis: Thanks! This makes a lot of sense when trying to dynamically load a component. However, this doesn't get me all the way to what I'm specifically looking to do. I might need to create a new item for that...I'm specifically trying to load a module that specifies routing information and would add this information to the routing table (under a specific parent route that I would need to specify).
jelbourn commentedon Oct 9, 2020
Tracking the main underlying concern here in #18093
This has been partially addressed by Ivy (the part where the Angular compiler has to know about everything in one run)
angular-automatic-lock-bot commentedon Nov 9, 2020
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.