In my ionic project, I am getting html in json dynamically as below:
@ViewChild('main', { read: ViewContainerRef }) entry: ViewContainerRef;
ngOnInit(){
this.API.get_item_REST().then((res)=>{
let myTemplate = res['html']; //Simple html: <div>Test</div>
@Component({
template: myTemplate
})
class dynamicComponent {
constructor(){}
}
@NgModule({
imports: [BrowserModule,IonicModule],
declarations: [dynamicComponent]
})
class dynamicModule {};
const mod = this.compiler.compileModuleAndAllComponentsSync(dynamicModule);
const factory = mod.componentFactories.find((comp) =>
comp.componentType === dynamicComponent
);
this.entry.createComponent(factory);
})
};
It works fine on ionic serve -l
but when I build it ionic cordova build android --prod
and test it on the phone, it doesn’t show any dynamic content.
Any thoughts?