i was trying to declare a component as Form Control.
<my-child-component formControlName="selectedSeats"></my-child-component>
Based on this answer i tried something like this using ControlValueAccessor,
public propagateChange: any = () => {};
public validateFn: any = () => {};
get selectedClasses() {
return this.myForm.get('selectedSeats').value;
}
set selectedClasses(val) {
this.propagateChange(val);
}
public ngOnChanges(inputs) {
}
public writeValue(value) {
}
public registerOnChange(fn) {
this.propagateChange = fn;
}
public registerOnTouched(fn) {
}
public validate(c: FormControl) {
return this.validateFn(c);
}
I am trying to pass the value of this.myForm.get('selectedSeats').value as component value and trying to bind to formcontrolname. But this code not working neither not throwing error.
could someone please tell me how to set this.myForm.get('selectedSeats').value value as my-child-component value and pass to formcontrol ?
parent component is Dynamic reactive nested form. inside the parent form i am calling another child-component which has its own set of form and it will return one value and it will be stored on selectedSeats input field. So now i need to pass that field value to parent and bind on parent nested form using formcontrol.
provide: [{NG_VALUE_ACCESSOR,useExisting: forwardRef(() => CustomInputComponent), multi: true}]
– Shadowlauch