Customizing module loader
The built-in application module loader uses SystemJS
. But we can provide our own implementation of the loader as follows:
@NgModule({ //... bootstrap: [MailAppCmp], imports: [RouterModule.forRoot(ROUTES)], providers: [{provide: NgModuleFactoryLoader, useClass: MyCustomLoader}] }) class MailModule {} platformBrowserDynamic().bootstrapModule(MailModule);
You can look at SystemJsNgModuleLoader to see an example of a module loader. Finally, you don't have to use the loader at all. Instead, you can provide a callback the route will use to fetch the module.
{ path: 'contacts', loadChildren: () => System.import('somePath'), }