I am looking to implement Angular 4 validation dynamically based on specific conditions within a Reactive form. Here is the scenario:
There is a radio button with options: A: yes B: no
If the user selects "yes"
, a textbox (formControlName="your_name"
) will be displayed where the user can enter their name.
I need to apply dynamic validation so that if the user selects "yes"
from the radio button, the field "your_name"
should be required; otherwise, it should not be mandatory.
How can I achieve this dynamic validation?
fb.group({
your_name: ['', Validators.required]
});