Nowaday I´m creating this formBuilder:
return this.fb.group(
{
myaccount: [ '', [Validators.required]]
}
);
When I´m getting the error message for element I´m doing:
Object.keys(formToValidate.controls).forEach(key => {
const controlErrors: ValidationErrors = formToValidate.get(key).errors;
if (controlErrors != null) {
Object.keys(controlErrors).forEach(keyError => {
if (keyError === 'required') {
console.log('Key control: ' + key + ', keyError: ' + keyError + ', err value: ', controlErrors[keyError]);
}
});
}
});
Display: Key control: myaccount, keyError: required, err value: true
The problem is I dont want to display 'myaccount' but 'My Account'. I tried in some way to do this:
return this.fb.group(
{
myaccount: [ 'My Account','', [Validators.required]]
}
);
but this is not possible. How can I do this?
EDIT:
I want to display label (Specific one) and not the value on the form. I want to customize a specific name for my console.log?
myaccount: [ 'My Account', [Validators.required]]
– Eliseomyaccount
is the formControl name andMy Account
is theformcontrol
Value . So to display the value just use :formToValidate.get(key).value
– CruelEngine