-
-
Save jorroll/7f5e47b57ba99cf014d77e27c5463a1e to your computer and use it in GitHub Desktop.
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
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