-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Description
Right now, there's only one official Angular CLI way to dynamically load NgModule; through the router configuration and the discovery process for lazy routes.
This discussion is not about dynamic loading of TypeScript files, which works properly already, using the import()
keyword. This is exclusively when splitting code at the NgModule boundary, which isn't currently supported.
This has as a consequence that people have to use a fake route if they want to split at the NgModule boundary; e.g. AIO here. Although this work, it's a bad pattern that users shouldn't have to do.
The current suggested design is:
- Allow users to add entries to the lazy route from the configuration to emulate the ROUTES provider, then
- Use
NgModuleFactoryLoader
(see example in AIO here) to load the module, which supports both JIT and AOT.
Alternative design was to add refactoring/support of import()
keyword, with some annotation support to tell if we should rename to import on AOT. This would require changes in the Angular Compiler which would only make this compatible with Angular 6, while the solution above is fully compatible with Angular 5.