Lets say
surname = new FormControl('', [Validators.required, Validators.minLength(2)]);
At some point depending on the situation I may add or delete any validators on surname control.
At the end How do I know what validators exists on surname control? I couldn't find any thing in documentation nor by dumping the control into console
Something like
surname.getValidators() should return - ['required', 'minLength']
We can add Validators dynamically using the SetValidators or SetAsyncValidators. This method is available to FormControl, FormGroup & FormArray. There are many use cases where it is required to add/remove validators dynamically to a FormControl or FormGroup.
To fetch the value of a form control, we have to use value property on the instance of FormControl in our class. In the same way we can fetch the value in HTML template. city = new FormControl('Noida'); console.
FormArraylink. Tracks the value and validity state of an array of FormControl , FormGroup or FormArray instances.
FormBuilder allows us to explicitly declare forms in our components. This allows us to also explicitly list each form control's validators. In our example we are going to build a small form with three inputs, user name, email and profile description. We will start with looking at our app.
Reading validators from a control is currently not supported
See also https://github.com/angular/angular/issues/13461
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With