angular - Dynamically Load Angular2 Modules -


i have created angular2 application, bundling using webapack. destination file size got increased more 15mb including depending modules.

now want load dependency modules based on demand.

i have multiple main menu's, each menu contains module related components. asynchronously load dependency module based on user menu selection.

you can using dynamic module loading , jit compiler. here general approach:

constructor(private injector: injector, private compiler: compiler)  loadmodule(modulename) {     import(pathtomodule).then((module)=>{         const moduleclass = module.modulename;         const modulefactory = this.compiler.compilemodulesync(moduleclass);         const moduleref = modulefactory.create(this.injector);         const componentfactoryresolver = moduleref.componentfactoryresolver;          // can use resolver components         const f = componentfactoryresolver.resolvecomponentfactory(mycomponent);     }) } 

read more dynamic components int here need know dynamic components in angular


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -