Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. app
  2. plugins
  3. > test.module.ts
  4. plugin-holder
  5. > plugin-holder.component.ts
  6.  
  7. ngOnInit(){
  8. this.route.params.subscribe((params: Params) => {
  9. this.id = params["id"];
  10. this.loadPlugin({
  11. componentName: "TestComponent",
  12. // modulePath: "D:/jonio/Dokumente/Programmieren/1GAMES/Overlay-R/plugins/netflix/netflix.module.ts#NetflixModule"
  13. modulePath: "./app/plugins/test.module#DynamicModule"
  14. })
  15. })
  16. }
  17.  
  18. loadPlugin(plugin: Plugin){
  19. let injector = ReflectiveInjector
  20. .fromResolvedProviders([], this.viewref.parentInjector);
  21. // Create module loader
  22. let loader = new SystemJsNgModuleLoader(this.compiler);
  23. loader.load(plugin.modulePath) // load the module and its components
  24. .then((modFac) => {
  25. // the missing step, need to use Compiler to resolve the module's embedded components
  26. this.compiler.compileModuleAndAllComponentsAsync<any>(modFac.moduleType)
  27.  
  28. .then((factory: ModuleWithComponentFactories<any>) => {
  29. return factory.componentFactories.find(x => x.componentType.name === plugin.componentName);
  30. })
  31. .then(cmpFactory => {
  32.  
  33. // need to instantiate the Module so we can use it as the provider for the new component
  34.  
  35. let modRef = modFac.create(this.viewref.parentInjector);
  36. this.cmpRef = this.viewref.createComponent(cmpFactory, 0, modRef.injector);
  37.  
  38. // done, now Module and main Component are known to NG2
  39.  
  40. });
  41. });
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement