These docs state the following:
If emitEvent is true, this change will cause a valueChanges event on the FormControl to be emitted. This defaults to true (as it falls through to updateValueAndValidity).
What is this updateValueAndValidity
?
These docs state the following:
If emitEvent is true, this change will cause a valueChanges event on the FormControl to be emitted. This defaults to true (as it falls through to updateValueAndValidity).
What is this updateValueAndValidity
?
You can subscribe to value changes of a control or the whole form.
updateValueAndValidity
allows you to modify the value of one or more form controls and the flag allows you to specify if you want this to emit the value to valueChanges
subscribers.
The sourcecode can be helpful to clear up exactly what it's doing:
https://github.com/angular/angular/blob/master/packages/forms/src/model.ts
Currently it seems to be doing the following (this list is based on method names):
.status
'VALID' except if ALL controls are disabled, in which case it makes it 'DISABLED'.value
if the control is enabled, or clear it if disabled.value
and status
normal form events.onlySelf
is set.Note: it doesn't go down the tree, only up.
I wish they'd put something like this in the docs. They currently say 'Recalculates the value and validation status of the control.' which isn't particularly helpful.
The updateValueAndValidity()
method belongs to the AbstractFormControl class, used to validate your forms programmatically.
Basically, when you add or remove a validator at run time, you must call updateValueAndValidity()
for the new validation to take effect.