Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load and unload modules programmatically in Angular 2

I'm thinking about migrating a large web application 'SPA' I wrote in angular 1 to angular 2,

The application contains hundreds of modules and this number can go way up because the community can upload new modules, so loading every module for every section up front is out of the question.

In AngularJs 1.x, I managed to programmatically load (Lazy loading using $compile) and unload (using $destroy) scopes and views "modules", and everything's working smoothly..

So, my question is how to achieve this in Angular 2 (currently using rc1) ? How to dynamically load modules, and unload them when the user is done ?

like image 910
Chtiwi Malek Avatar asked May 04 '26 23:05

Chtiwi Malek


1 Answers

Probably you can use DynamicComponentLoader for your requirement. It supports conditional Loading of multiple components too. For more referrence you can follow This Plunker too.

You can load multiple components whenever required and unload them too.

Hope this helps.

like image 56
Bhushan Gadekar Avatar answered May 06 '26 11:05

Bhushan Gadekar