问题
I can dynamically load local modules as someone else did in the plunker here. But how do I load an external module, lets say from a separate bundle js served by another service. In the example plunker, src/app.ts has:
constructor(private viewref: ViewContainerRef,
private resolver: ComponentFactoryResolver,
private loader: SystemJsNgModuleLoader,
private compiler: Compiler){
this.module = new ModuleNode();
//can I make this a non-local script reference somehow?
//like to http://example.net/external.module.bundle.js
this.module.modulePath = "src/dynamic.module#DynamicModule";
this.module.componentName = "TestComponent";
}
Is there any way to achieve this?
EDIT: To clarify, the scenario is that a group of microservices (built, deployed, etc. independently) are making a spa. So my microservice wants to dynamically load a component/ module from a bundle.js served by another microservice. This is why I don't have the module/ bundle at compile time. The only contract between the two microservices is the url to the bundle file. If they update the component/ module, a hard refresh should reflect the changes without a re-deployment of my microservice.
来源:https://stackoverflow.com/questions/42401013/how-to-dynamically-load-external-angular-2-module-like-served-from-an-external