I am working on implementing a new feature for my app that involves storing certain modules on the backend and loading them dynamically based on user demand. Instead of loading all modules at once, I want to only load the necessary modules just before the page is loaded. However, I am facing challenges in figuring out the best way to implement this functionality. The Lazy Loading example in Angular 2 Docs uses routes to lazy load modules, which is not suitable for my needs as I need to be able to load modules directly from the database. Additionally, some examples suggest using entry components, but these methods seem to be deprecated and not all of my modules have components.
Can anyone provide guidance on how to manually load and connect modules from the backend? To give more context, I have a service that represents each tool, with properties that hold the class of the component associated with that tool:
export class CtSelectionTool implements ConnectableTool {
.....
plotterComponent: any = CtSelectionToolComponent;
.....
}
Currently, after a page loads, I iterate over the loaded services and dynamically create the components for each tool where they are needed. These components are declared in their respective modules. My goal is to find a way to only load these modules when the corresponding tool is requested by the user.