hoeni
hoeni

Reputation: 3300

Programmatic loading of modules in Angular 8+ (and Ivy-ready?)

My application needs to load a dynamically configured set of feature modules (each with own, additional routes) that are individually defined by a config file (loaded with XHR). My original plan was to have a list of module strings (like "plugins/my.module#MyModule") and use NgModuleFactoryLoader.load() to load them while bootstrapping.

Now, when I started implementing, I saw NgModuleFactoryLoader is beeing deprecated in favour of the import() form of LoadChildren, which will not work in this context (I have only strings in config, no module refs).

How could I implement this in current (8+) Angular?

Upvotes: 1

Views: 1308

Answers (2)

user10123947
user10123947

Reputation:

This is quite a big topic but the NgModuleFactoryLoader will not work anymore if you're using the Ivy compiler. Because there are no module factories anymore, only injector definitions on module classes.

There is completely new Ivy API and it will not fit in this answer by its size.

As you've asked me in comments to leave an answer thus the next researcher will find it easier. That's the link to the Asynchronous Modules and Components in Angular Ivy article. It's also available on the indepth.dev if the Medium link is gone.

Upvotes: 3

eduardo panero
eduardo panero

Reputation: 24

The new form to implement LazyLoading with import is something like this

  {
    path: '',
    loadChildren: () =>
      import('./dashboard/dashboard.module').then(
        mod => mod.DashboardModule
      )
  }

You must import the module file with the path and then select the Module implementation

Upvotes: 0

Related Questions