Skip to content

Instantly share code, notes, and snippets.

@jorroll
Created November 4, 2019 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorroll/7f5e47b57ba99cf014d77e27c5463a1e to your computer and use it in GitHub Desktop.
Save jorroll/7f5e47b57ba99cf014d77e27c5463a1e to your computer and use it in GitHub Desktop.
const nameControl = new FormControl('');
nameControl.patchValue('John');
control.value; // => 'John'
control.errors; // => null
control.touched; // => false
control.markTouched(true);
control.touched; // => true
const validator: ValidatorFn = control => {
if (control.value.length < 2) {
return {
tooShort: 'Must be at least 2 characters',
};
}
return null;
};
control.setValidators(validator);
// get the current value as well as changes
control.observe('value').subscribe(value => {
// do stuff
});
// just get changes
control.observeChanges('errors').subscribe(errors => {
// do stuff
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment