Join Justin Schwartzenberger for an in-depth discussion in this video Built-in validators, part of Angular 2 Forms: Data Binding and Validation.
- [Instructor] Angular has support for validation logic…at all of the fundamental building blocks for forms,…formControl, formGroup and formArray.…You can wire up validation for these…by passing in a validator function when you create them.…Angular provides a set of validator functions…as part of the platform…like required, min and max length and pattern.…These functions exist on a class named validators…that is exported from the Angular forms scoped packaged,…just like the rest of the Angular form goodies.…
In the order sheet component TS file,…up in the import statement…for the Angular form scope package,…I can add validators to the list…to make use of some of the built-in ones.…And then down in the buildForm method,…I'm going to add a required validator…onto the customer name formControl.…The formBuilder.control method accepts a validator function…as the second parameter.…So I can set the second argument in the call here…to be validators.required.…
So this formControl is now required to have a value,…but it would be helpful to give the user…
Updated
12/7/2016Released
6/27/2016This course shows how to build HTML web forms using the building blocks, built-in validation properties, and methods of the Angular forms module. Learn how to use the model-driven forms approach to build out a model representation of form data in code and bind it to native HTML form elements. This course also explores how to implement validation, using JavaScript, in case you need more fine-tuned control of your interactions.
- Building an Angular form
- Creating a model-driven form
- Using form building blocks: Controls, groups, and arrays
- Handling different input types: Text, checkboxes, selections, and radio input
- Adding change detection to your forms
- Creating custom validations
Share this video
Embed this video
Video: Built-in validators