Inside my angular app I generated a component that serves as a custom FormControl
and it implements ControlValueAccessor
and Validator
.
That component is used inside a FormGroup
and it has a validator attached to it (like its value must have at least 10 chars or w/e). When theres a value change inside the actual input
inside my custom FormControl
the validate
method triggers. Inside this method I can access the FormControl
but it has a "pre-change-state" i.e. if the user typed in something wrong (according to the bound validator) it gives me its last value/error/state...
To get to the updated state I'm using a hacky
setTimeout(()=>{// code goes here},0);
How can I get the updated state inside validate
without setTimeout
? Or is there something like an afterUpdate
hook I am not aware of?
Here's my stackblitz: https://stackblitz.com/edit/angular-8-material-starter-template-tubfwx?file=src%2Fapp%2Fcustom-form-control%2Fcustom-form-control.component.ts