Answer the question
In order to leave comments, you need to log in
How can the ngIf condition be shortened if only one property in the condition changes?
There is such a condition, but it is very large and only one property is always repeated: firstName
<span *ngIf="registrationForm.controls.firstName.errors && registrationForm.controls.firstName.errors.required && registrationForm.controls.firstName.touched" class="clr-subtext">This field is required</span>
<span *ngIf="registrationForm.controls.email.errors && registrationForm.controls.email.errors.required && registrationForm.controls.email.touched" class="clr-subtext">This field is required</span>
Answer the question
In order to leave comments, you need to log in
isFieldRequired(field: string): boolean {
const control = this.registrationForm.controls[field];
return control.errors && control.errors.required && control.touched;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question