У меня есть электронное приложение, работающее на angular 6, и я пытаюсь получить что-то вроде системы плагинов.Я бы лениво загружал каждый модуль плагина из уже известного местоположения, а затем использовал его основной компонент.
Структура моей папки:
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
});
});
}
но я всегда получаю сообщение об ошибке, что модуль не может быть загружен.
У вас есть идея, почему это не работает?