I am creating a dynamic component angular. How can I catch the error of rendering the template of this component
@ViewChild('vc', { read: ViewContainerRef }) _container: ViewContainerRef;
private insertDynamicComp() {
this._container.clear();
this.generateComponent(this.element.data).then((view) => {
this._container.insert(view);
});
}
private generateComponent(template: string): Promise<ViewRef> {
return new Promise((resolve, reject) => {
try {
const _this = this;
const tmpCmp = Component({
template: template || '',
changeDetection: ChangeDetectionStrategy.OnPush,
})(DynamicClass);
const tmpModule = NgModule({
declarations: [tmpCmp],
})(class {});
const t = this._compiler.compileModuleAndAllComponentsSync(tmpModule);
const f = t.componentFactories[0];
const cmpRef = f.create(this._injector, [], null, this._m);
cmpRef.instance.SetParentFunction(_this);
resolve(cmpRef.hostView);
} catch {
reject(null);
}
});
}
I would be grateful for any help. Thanks