How to dynamically load external angular 2 module (like served from an external module.bundle.js)

◇◆丶佛笑我妖孽 提交于 2019-12-03 12:41:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!