I am trying to dynamically load template for one of my component. Below is a code snippet I have written. This works fine in development mode. But in production it fails. Probably due to AOT.
ngAfterViewInit(): void {
const moduleName = this._module.instance.constructor.name;
const tmpCmp = Component({
moduleId: moduleName,
templateUrl: '/assets/templates/faqs/faqs.' + environment.vendor_prefix + '.component.html'
})(class {});
const tmpModule = NgModule({ declarations: [tmpCmp] })(class {});
this._compiler.compileModuleAndAllComponentsAsync(tmpModule).then(factories => {
const factory = factories.componentFactories[0];
const cmpRef = factory.create(this._injector, [], null, this._module);
cmpRef.instance.name = 'dynamic';
this.vc.insert(cmpRef.hostView);
});
}
I am getting an error message as Runtime compiler is not loaded.
I tried searching for a solution on stackoverflow but got some unanswered questions. Can someone help me with this?