minlength validator causes ExpressionChangedAfterItHasBeenCheckedError when its value is dynamically updated #24251
Labels
area: forms
freq2: medium
P3
An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
state: confirmed
type: bug/fix
workaround2: non-obvious
Milestone
I'm submitting a...
Current behavior
When an input field has a minlength validator directive and minlength value dynamically changes this causes ExpressionChangedAfterItHasBeenCheckedError when the field turns from valid to invalid, and vice-versa, and if you additionally check form validity with *ngIf above the input field. Strangely, when you check form validity below the field with *ngIf there is no error.
Expected behavior
There shouldn't be ExpressionChangedAfterItHasBeenCheckedError after minlenght validation returns a result and field changes state (valid/invalid).
Minimal reproduction of the problem with instructions
Here is a demo which demonstrates the problem and also cases where there is no problem. All the details are described in the demo.
What is the motivation / use case for changing the behavior?
It should be possible to dynamically change the value for validation without bumping into ExpressionChangedAfterItHasBeenCheckedError.
Environment
The text was updated successfully, but these errors were encountered: