-
-
Save Piterden/78782b5fe8ffa38d54ea617f94224e41 to your computer and use it in GitHub Desktop.
Naive and buggy approach to dynamic validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.myForm.get('myCheckbox').valueChanges.subscribe((value) => { | |
if (value) { | |
this.myForm.get('myEmailField').setValidators(Validators.required); | |
} else { | |
this.myForm.get('myEmailField').clearValidators(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment