Handling Validation
In this lesson, we'll learn how to handle validation if the user inputs an invalid value.
We'll cover the following...
We’re able to validate the input successfully. However, the way we’re telling the user isn’t the most magnificent way. We’ll want to provide friendlier feedback to the user. When it comes to handling feedback, Angular expects us to handle outputting the message. It will not generate a message for us.
It’s going to require some extra work, but Angular provides us with all the information we’ll need to generate a message.
Retrieving the validation errors
Currently, we’re checking if the form is valid by checking the valid
property on the form group. If we want to check validation on an individual controller, we’ll need to access the controller via the group’s controls
property. This will be an object of the controllers registered in the group.
ccForm.controls.name.errors
Every controller can be accessed via its key name. We’re accessing an object on the controller called errors
. This will be an object of the validation rules broken by the input value.
Alternatively, we can use a method, called get()
, on the form group. This will have one argument, which is the name of the ...