- Which method is used to add dynamic validation to the forms?
- How to validate dynamically created textbox in Angular?
Which method is used to add dynamic validation to the forms?
The FormGroup class exposes an API that enables us to set validators dynamically. We need to listen to optionB value changes and based on that we add or remove the validators we require. We also call the control's updateValueAndValidity() method, as we need to recalculate the value and validation status of the control.
How to validate dynamically created textbox in Angular?
I check input text fields validations in angular normally by giving a template reference variable ngmodel to the input tag such as #name1="ngModel" then using that variable as such *ngIf="name1. touched && ! name1. valid" to check for its validity and display an error message accordingly.