Outline
- Intro to Reactive Forms in Angular - Course Introduction
- Intro to Reactive Forms in Angular - FormControl Foundations
- Intro to Reactive Forms in Angular - Building a Form with Groups
- Intro to Reactive Forms in Angular - Simplify Form Creation
-
Intro to Reactive Forms in Angular - Make Forms Dynamic
- Introduction
- Demo: FormArray with FormControls in the Component
- Exercise: Fix the Errors! FormArray with FormControls
- Solution: Fix the Errors! FormArray with FormControls
- Demo: FormArray with FormControls in the Template
- Exercise: FormArray with FormControls
- Solution: FormArray with FormControls
- Demo: Removing Items from a FormArray
- Demo: FormArray with FormGroups
- Exercise: FormArray with FormGroups
- Solution: FormArray with FormGroups
- Wrap Up
-
Intro to Reactive Forms in Angular - Validate Forms
- Introduction
- Demo: Built-in Validators
- Exercise: Built-in Validators
- Solution: Built-in Validators
- Demo: Adding Error Messages
- Exercise: Adding Error Messages
- Solution: Adding Error Messages
- Styling Controls for Validity
- Update Validators Dynamically
- Demo: Custom Validators
- Exercise: Custom Validators
- Solution: Custom Validators
- Demo: Cross-field Validation
- Exercise: Cross-field Validation
- Solution: Cross-field Validation
- Wrap Up
- Intro to Reactive Forms in Angular - Course Wrap Up
-
Let's Code Together - Building a Search Form
- Introduction
- Code Walkthrough and First Assignment
- Add ReactiveForms Module
- Create Initial Form
- Call Search Method
- Name Searching
- Using Select with Reactive Forms
- Implement League Search
- Implement Game Night Search
- Implement Recruiting Search
- Implement Coed Search
- Implement Max Search Fee
- Implement Record Search & Summary
-
Lets Code Together - Building an Edit Form with Reactive Forms
- Introduction
- Demo Code Walkthrough
- First Assignment
- Create the Basic Form
- Hook Up Form Events
- Show & Hide the Form
- Set the Name on Edit
- Save Changes to Name
- Set and Save GameNights
- Set and Save Max Teams & Coed
- Set seasonStarts & seasonEnds
- Save sasonStarts & seasonEnds
- Set & Save the Contact Emails
- Adding New Contact Emails
- Deleting Contact Emails
- Lets Code Together - Validating an Edit Form with Reactive Forms
Outline
- Intro to Reactive Forms in Angular - Course Introduction
- Intro to Reactive Forms in Angular - FormControl Foundations
- Intro to Reactive Forms in Angular - Building a Form with Groups
- Intro to Reactive Forms in Angular - Simplify Form Creation
-
Intro to Reactive Forms in Angular - Make Forms Dynamic
- Introduction
- Demo: FormArray with FormControls in the Component
- Exercise: Fix the Errors! FormArray with FormControls
- Solution: Fix the Errors! FormArray with FormControls
- Demo: FormArray with FormControls in the Template
- Exercise: FormArray with FormControls
- Solution: FormArray with FormControls
- Demo: Removing Items from a FormArray
- Demo: FormArray with FormGroups
- Exercise: FormArray with FormGroups
- Solution: FormArray with FormGroups
- Wrap Up
-
Intro to Reactive Forms in Angular - Validate Forms
- Introduction
- Demo: Built-in Validators
- Exercise: Built-in Validators
- Solution: Built-in Validators
- Demo: Adding Error Messages
- Exercise: Adding Error Messages
- Solution: Adding Error Messages
- Styling Controls for Validity
- Update Validators Dynamically
- Demo: Custom Validators
- Exercise: Custom Validators
- Solution: Custom Validators
- Demo: Cross-field Validation
- Exercise: Cross-field Validation
- Solution: Cross-field Validation
- Wrap Up
- Intro to Reactive Forms in Angular - Course Wrap Up
-
Let's Code Together - Building a Search Form
- Introduction
- Code Walkthrough and First Assignment
- Add ReactiveForms Module
- Create Initial Form
- Call Search Method
- Name Searching
- Using Select with Reactive Forms
- Implement League Search
- Implement Game Night Search
- Implement Recruiting Search
- Implement Coed Search
- Implement Max Search Fee
- Implement Record Search & Summary
-
Lets Code Together - Building an Edit Form with Reactive Forms
- Introduction
- Demo Code Walkthrough
- First Assignment
- Create the Basic Form
- Hook Up Form Events
- Show & Hide the Form
- Set the Name on Edit
- Save Changes to Name
- Set and Save GameNights
- Set and Save Max Teams & Coed
- Set seasonStarts & seasonEnds
- Save sasonStarts & seasonEnds
- Set & Save the Contact Emails
- Adding New Contact Emails
- Deleting Contact Emails
- Lets Code Together - Validating an Edit Form with Reactive Forms
Now let's a create a FormArray containing FormGroups instead of FormControls. Each FormGroup will have 2 FormControls: a phone number and a phone type.
Changes in the Component:
To start, we’re going to rename createPhoneControl() to createPhoneGroup(), and instead, we’ll return a FormGroup():
createPhoneGroup() { return this.fb.group({ phoneNumber: '', phoneType: '' }); }
Since we want phoneTypes to be a select dropdown, we'll initialize the default values at the top of the component as a string array.
phoneTypes: string[] = ['Mobile', 'Home', 'Other'];
We also need to add a method that updates the form when phoneType is updated. Let’s call it pickPhoneType(), which takes in an event that we’ll pass from the template. This will be the new phoneType value that the user selects. The patchValue() method allows us to partially update the form rather than update the entire form, like setValue() does.
pickPhoneType(event): void { this.regForm.patchValue({phoneType: event.target.value}) }
Changes in the Template:
Inside the FormArray div, we'll add another div for the FormGroup and bind it to the index:
[formGroupName]="i"
Each FormControl requires a directive of formControlName
set to their associated FormControl keys. We'll add (change)=pickPhoneType($event)
to the select tag to update on change. Finally, the option tag will iterate over the phoneTypes and property bind the type to [ngValue].