Skip to content

Instantly share code, notes, and snippets.

@Piterden
Forked from ganqqwerty/app.component.ts
Last active June 19, 2019 21:01
Show Gist options
  • Save Piterden/78782b5fe8ffa38d54ea617f94224e41 to your computer and use it in GitHub Desktop.
Save Piterden/78782b5fe8ffa38d54ea617f94224e41 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