requiredwhen
RequiredWhen is a custom validation strategy used in Angular reactive and template‑driven forms to conditionally mark a form control as required based on the value of another control or a set of controls in the same form group. The directive or custom validator monitors the dependent control(s) and applies the required validator only when a specified condition is met, thereby enabling dynamic form validation rules that respond to user input.
In a reactive form, the RequiredWhen validator can be implemented as a factory function that receives the
In template‑driven forms, the same concept is achieved by adding a [requiredWhen] directive to the input element
Documentation for both approaches includes examples of handling multiple dependencies, synchronous and asynchronous validation, and integration