Answer the question
In order to leave comments, you need to log in
How to implement ControlValueAccessor?
I asked the question How to pass the FormControlName to the component and the respected denismaster answered me there, what should be implemented ControlValueAccessor
and yes. I read about it and yes, I’m very ashamed, but I didn’t understand a damn thing how to transfer parameters through it to the
Stackblitz component
<form [formGroup]="SignupReactiveForm">
<div class="form-group">
<app-input label="email" type="email" formControlName="email">
</app-input></div>
</form>
<app-input label="email" type="email" formControlName="email">
InputComponent
I connect ControlValueAccessor
, I somehow implement this interfacewriteValue(value: any) {
this.formControlName = value;
}
registerOnChange() { }
registerOnTouched() { }
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => InputComponent),
multi: true
}
writeValue
the formControlName value and how do I output it??? Answer the question
In order to leave comments, you need to log in
Hello.
I will rely on your own code.
The implementation of this interface allows the Angular form to interact with the custom component. The method
writeValue(value: any) {
this.formControlName = value;
}
form.setValue({email: "email", password: 'passworddd'})
// или
form.patchValue({email: "email"})
this.filterForm.valueChanges
.pipe(
takeUntil(this._onDestroy$)
)
.subscribe((val) => {
console.log(val);
});
initForm() {
this.SignupReactiveForm = this.fb.group({
password: ['password', [
Validators.required,
Validators.pattern(/[A-z]/)
]
],
email: ['email', [
Validators.required, Validators.email
]
],
});
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question