Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app
- plugins
- > test.module.ts
- plugin-holder
- > plugin-holder.component.ts
- ngOnInit(){
- this.route.params.subscribe((params: Params) => {
- this.id = params["id"];
- this.loadPlugin({
- componentName: "TestComponent",
- // modulePath: "D:/jonio/Dokumente/Programmieren/1GAMES/Overlay-R/plugins/netflix/netflix.module.ts#NetflixModule"
- modulePath: "./app/plugins/test.module#DynamicModule"
- })
- })
- }
- loadPlugin(plugin: Plugin){
- let injector = ReflectiveInjector
- .fromResolvedProviders([], this.viewref.parentInjector);
- // Create module loader
- let loader = new SystemJsNgModuleLoader(this.compiler);
- loader.load(plugin.modulePath) // load the module and its components
- .then((modFac) => {
- // the missing step, need to use Compiler to resolve the module's embedded components
- this.compiler.compileModuleAndAllComponentsAsync<any>(modFac.moduleType)
- .then((factory: ModuleWithComponentFactories<any>) => {
- return factory.componentFactories.find(x => x.componentType.name === plugin.componentName);
- })
- .then(cmpFactory => {
- // need to instantiate the Module so we can use it as the provider for the new component
- let modRef = modFac.create(this.viewref.parentInjector);
- this.cmpRef = this.viewref.createComponent(cmpFactory, 0, modRef.injector);
- // done, now Module and main Component are known to NG2
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement