Watching state changes and being reactive
So far, we have learned how to create forms programmatically and how to specify all our fields and their validations in the code. A reactive form can listen to changes in the controls of the form when they happen and react accordingly. A suitable reaction could be to disable/enable a control, provide a visual hint, or something else according to your needs. You get the idea.
How can we make this happen? Well, a FormControl
instance contains two observable properties: statusChanges
and valueChanges
. The first one notifies us when the status of the control changes, such as going from invalid
to valid
. On the other hand, the second one notifies us when the value of the control changes. Let's explore this one in more detail, using an example.
The password
field in the ReactiveLoginComponent
form contains a validator to check the minimum length of the value entered by the user. From an end user point of view, it would be better to display...