6

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.

Anshuman Jaiswal
  • 5,352
  • 1
  • 29
  • 46
  • This might be helpful to you: https://stackoverflow.com/questions/42093101/angular2-with-typescript-how-to-use-plupload-cdn-script-file-in-lazy-loaded-mod – Sumit Agarwal Sep 21 '17 at 06:24
  • do you use angular cli? do you want to load a router module? – Max Koretskyi Sep 21 '17 at 07:38
  • Not yet, my goal is to use aot later. I want to use lazy-loading to load a module from external source (using http//mydomain.com/module). This module could be compiled js? Perfect solution would be to use dynamic routes and that this module could be attached with its own children routes. For example on /externalModule, I grab the module from http//externalMdoule and this module adds a children routing to allow to access /externalModule/page1 /externalModule/page2 where page1 and page2 are components downloaded with the module – zagubionytroll Sep 21 '17 at 12:28
  • Did you resolved? @zagubionytroll – Dani Andújar Nov 08 '17 at 10:07
  • @user3757628 unfortunately not – zagubionytroll Mar 21 '18 at 09:58

1 Answers1

0

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

Jeba Prince
  • 1,669
  • 4
  • 22
  • 41