October 2017
Intermediate to advanced
280 pages
6h 50m
English
We took a look at how we can apply a single validator to form controls. Using the model-driven approach, we applied the Validators.required validator in a way equivalent to what we did in the previous chapter, where we used template-driven forms and added the required attribute. However, in some applications, the domain may require a more complex validation logic. For example, if we want to apply both the required and the validateEmail validators to the email control, we should do the following:
this.addDevForm = fb.group({
...
email: ['', Validators.compose([
Validators.required,
validateEmail ]) ],
...
});
The compose method of the Validators object accepts an array of validators as an argument and ...
Read now
Unlock full access