In this video, learn how to create a custom validator and how to return error data from it.
- [Instructor] Okay, let's build a custom validator. … To build your own custom validators, … you need to create a function that will receive an object. … Which, Angular will pass in as … either a form control, form group, or form array. … And that function needs to return … null when valid and return an object if invalid. … Let's build a year validator for the … year field, which is a form control. … In the media dash item dash form dot component dot ts file, … we can create a method named year validator. … And give it a parameter named control, … that we can set to a type of form control. … We want the year field to be optional so … the first bit of logic we will add is to … check if the value's empty and, if so, return null, … telling the control that the field is valid. … If it makes it past that, we want to convert the value, … which is a string, into a number. … So we can call parseInt on control dot value and … capture it to a local variable. … And then we will set up a min and max year. …
- What is Angular?
- Working with components
- Binding events and properties
- Getting data to components
- Using directives and pipes
- Creating Angular forms
- Validating form data
- How Angular does dependency injection
- Making HTTP calls
- Styling components
Skill Level Intermediate
Angular: Building an Interfacewith Ray Villalobos2h 20m Intermediate
1. Architecture Overview
3. Directives and Pipes
5. Dependency Injection and Services
8. Styling Components
Next steps1m 20s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.