Loading

Quipoin Menu

Learn • Practice • Grow

angular / Reactive Form Validation
interview

Q1. How do you set up validation in reactive forms?
Add validators as the second argument to FormControl. Example:
name: new FormControl('''', [Validators.required, Validators.minLength(3)])
For FormGroup, validators can be added as a second argument for cross-field validation.

Q2. How do you access form control states?
Use the control''s properties like valid, invalid, pending, dirty, pristine, touched, untouched. Example:
Error

Q3. How do you update validation dynamically?
Use setValidators or clearValidators methods. Then call updateValueAndValidity(). Example:
myForm.get(''email'').setValidators([Validators.required, Validators.email]); myForm.get(''email'').updateValueAndValidity();

Q4. How do you disable form controls?
Use the disable() method or set the disabled property in the FormControl options. Example:
email: new FormControl({value: '''', disabled: true})
Or programmatically: myForm.get(''email'').disable().

Q5. How do you reset a reactive form?
Use the reset() method on FormGroup. It can reset to specific values. Example:
myForm.reset(); myForm.reset({ name: ''Default'' });
This also resets validation state.