Aug 23, 2017 · 1 min read
Create a DynamicFormComponent component that uses ViewContainerRef and ComponentFactoryResolver to dynamically render a component that it’s passed as Input. Add an output isValid to it.
Use the same methods above in the rendered component to emit the valid state of the form to the parent by subscribing to the isValid and passing it to the dynamic components isValid output like so:
const comp = this._componentFactoryResolver.resolveComponentFactory(this.component);
const instance = this.container.viewContainerRef.createComponent(comp).instance;
instance['isValid'].subscribe(e => this.isValid.emit(e));