Skip to content

Instantly share code, notes, and snippets.

@ganqqwerty
Last active June 19, 2019 21:01
Show Gist options
  • Save ganqqwerty/de32ac46f4669f1aea6c92782f6e3258 to your computer and use it in GitHub Desktop.
Save ganqqwerty/de32ac46f4669f1aea6c92782f6e3258 to your computer and use it in GitHub Desktop.
Naive and buggy approach to dynamic validator
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