0

Anyone know if it's possible to load an external js file containing an Angular 2/4 module/component?

If so, how do you do, and how is that component/module compiled to that external js?

bjorkblom
  • 1,849
  • 3
  • 21
  • 31
  • you can look into this -https://stackoverflow.com/questions/40706572/angular2-lazy-loading-of-component-without-router-or-import – Aniruddha Das Sep 13 '17 at 17:19

2 Answers2

1

LoadChildren in routing is one of the best way used to load module and components in to angular project. If you are using cli, webpack will build your modules seperatly and they will be loaded dynamically at run time using router.

const routes: Routes = [
  { path: '', loadChildren: './some-folder/private.module#PrivateModule'},
  { path: 'login', component: LoginComponent }
];

Here for the blank route the private module, private component will be loaded dynamically.

Aniruddha Das
  • 20,520
  • 23
  • 96
  • 132
0

It is possible. Look here: https://blog.thecodecampus.de/angular-2-dynamically-render-components/ Instead of entering entryComponents array upfront I would try to do some magic with require('path_to_component').default .

proti
  • 213
  • 3
  • 11