Dynamic load external modules in angular2

Viewed 1317

I have node.js application that host an angular2 application. The whole application is using lazy loading like this:

export const routes: Routes = [
    {
        path: '', component: MyComponent,
        children: [
            {
                path: 'lazy',
                loadChildren: '../common/lazy/lazy.module#LazyModule'
            }
    }
]

The other team in my company is building another kind of software, but we want to reuse some of their modules. We don't want to share strictly code base, but rather host a module publicly and let it load by the application itself so we can do something like this

export const externalRoutes: Routes = [
    {
        path: 'externalModule',
        loadChildren: 'http://mymodules.host/lazy.module#LazyModule'
    }
]

Is is possible to load module in "live" application? I know there's something like dynamic component loader, but we need to load a module with plenty of components in it.

1 Answers

You can't load a module out side of your project for security reasons.

What you can do it, as the other team to create a Angular Library project

https://angular.io/guide/creating-libraries

and consume it as a module by adding it as a dependency in package.json

Related