Angular dynamic components issue in production mode (Aot)

Dears,

we have to compile and load Dynamic Components… works in dev but in production mode (AOT enabled) we get the error “template must be a string”.

APp config:

  • @angular/core”: “~9.1.6”,
  • @ionic/angular”: “^5.0.0”,
@Component({
 template: componentTemplate,
 selector: templateDef.name,
 })
 class TemplateComponent extends DynamicUiBaseComponent implements OnInit {
 
 ngOnInit() {
 super.ngOnInit();
 }
 }
....
this.compiler.compileModuleAndAllComponentsSync(DynamicModule);

you wrote in the Component declaration:

template: componentTemplate

What’s componentTemplate?

componentTemplate: string contains template generated at runtime

Yeah, you shouldn’t do that. Component definitions need to be lined at build time in order for the angular compiler to do its magic.

1 Like