Last active
June 19, 2019 21:01
-
-
Save ganqqwerty/de32ac46f4669f1aea6c92782f6e3258 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