Im trying to add the component and module dynamically as shown below
Component:
protected createNewComponent (tmpl:string) {
@Component({
selector: 'dynamic-component',
template: tmpl,
providers: [{provide: CustomDynamicComponent, useExisting CustomDynamicComponent}]
})
class CustomDynamicComponent implements IHaveDynamicData {
@Input() public entity: any;
};
// a component for this particular template
return CustomDynamicComponent;
}
Here tmpl template is a dynamic string.
Module:
protected createComponentModule (componentType: any) {
@NgModule({
imports: [
],
declarations: [
componentType
],
})
class RuntimeComponentModule
{
}
// a module for just this Type
return RuntimeComponentModule;
}
Here componentType is the component I want to create.
Now, creating component and module dynamically using
let type = this.createNewComponent(template);
let module = this.createComponentModule(type);
and compiling the markup using
this.compiler
.compileModuleAndAllComponentsAsync(module)
.then((moduleWithFactories) => {})
On compiling this code, Im observing typescript compilation errors as shown below.
How to get rid of this compilation error in angular version14.
Thanks

