Pavel
Pavel

Reputation: 708

Is it possible to load external modules at runtime in angular 4?

Background

The web application in question consists of a main part (sort of a framework) which is standard for all users and a number of modules, some of which are standard, but a certain number of them are user-specific.

Simply described the main standard program does standard things like communication and session logic, loads user-specific UI (layout, graphics) modules, which in turn make use of a set of modules (like buttons, tables etc.) which are standard for all users. The user-specific modules have common interface and function, differ only in layout and a number of standard modules used (one to ten, usually different ones). Number of user-specific modules varies by user (again, one to about ten).

We already have a solution like this implemented with a combination of libraries (jQuery, Require.js and Knockout.js being the main ones), and we struggle to come up with a similar functionality with Angular. Answer saying this is not possible and why would be a valid (if undesirable) one.

The Problem

I'd rather that the user-specific modules not be part of the project for a number of reasons:

Desired solution

The main program loads two sets of data - list of available user-specific modules, a configuration which defines which module should be used at which placeholder element.

The user-specific modules are loaded (via some factory, router, any solution goes), and are to be used like usual modules as far as possible, sharing a common interface. Importantly, they can make use of other standard modules from the standard project.

Upvotes: 1

Views: 292

Answers (1)

Avi
Avi

Reputation: 1964

This sounds like dependency injection issue. why not declare all modules ahead and only play with the modules that you are injecting. meaning, you can set mock/empty modules if don't want/need them, and replace them with real modules where you need them. that's the beauty of dependency injection.

Upvotes: 1

Related Questions