Dynamic Form validation is not working in Angular 6

1.2k Views Asked by At

Scenario: User want to retrieve email or reset password. Person will select respective option as per requirement. Submit button will get enable only when form is valid.

Problem: I want to dynamically update validation according to selected option. But it is not working. Definitely I'm missing something. I used clearValidators, but it is also not working. Here is the working code.

For testing use: email : [email protected] password: Test@1234

1

There are 1 best solutions below

1
On BEST ANSWER

Try updating the individual controls value and validity. For example

this.loginTroubleForm.get('email').updateValueAndValidity();

Do this for each control for which you are setting the validator to null.