Chapter 7. Working with forms
This chapter covers
- Understanding the Angular Forms API (NgModel, FormControl, FormGroup, form directives, FormBuilder)
- Working with template-driven forms
- Working with reactive forms
- Understanding form validation
Angular offers rich support for handling forms. It goes beyond regular data-binding by treating form fields as first-class citizens and providing fine-grained control over form data.
This chapter will start by demonstrating how you can implement a sample user registration form in pure HTML. While working on this form, we’ll briefly discuss the standard HTML forms and their shortcomings. Then you’ll see what the Angular Forms API brings to the table, and we’ll cover the template-driven and reactive approaches to creating forms in Angular.
After covering the basics, you’ll refactor the original version of the user registration form to use the template-driven approach, and we’ll discuss its pros and cons. Then we’ll do the same with the reactive approach. After that, we’ll discuss form validation. At the end of the chapter, you’ll apply this new knowledge to the online auction application and start implementing its search form component.