Create Event Form Setup
Let's create the form for creating events.
We'll cover the following...
Now that all our modules and packages are set up, we can create our form.
This is our code so far:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>LetsGetLunch</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="favicon.ico"> </head> <body> <app-root></app-root> </body> </html>
Google Maps API key
Update component
- Start by adding the following imports to 
EventCreateComponent:- 
FormBuilderis a class that’s used to help us create the various controls, known asFormControls, within our form. These controls are a part of aFormGroupwhich in our case represents our entire form. So our form is composed ofFormControlsthat are all a part of aFormGroupwhich we create usingFormBuilder. - 
MapsAPILoaderis a part ofAGM, which will be used to load the Google Places API. 
 - 
 
Press +  to interact
// src/app/event/event-create/event-create.component.tsimport { FormBuilder, FormGroup, Validators } from '@angular/forms';import { MapsAPILoader } from '@agm/core';
- Now inject the 
FormBuilderandMapsAPILoaderdependencies into our constructor 
Press +  to interact
// src/app/event/event-create/event-create.component.tsexport class EventCreateComponent implements OnInit {eventForm: FormGroup;constructor(private fb: FormBuilder, private gmaps: MapsAPILoader) { }ngOnInit(): void {}}
- Along with the dependencies, create a property 
eventFormof typeFormGroup. This is theFormGroupthat will contain all of theFormControlswithin our form. 
Add CreateForm method
From here, add a method to use our injected FormBuilder to create a form setting it to our local eventForm of type FormGroup.
Press +  to interact
// src/app/event/event-create/event-create.component.tscreateForm() {this.eventForm = this.fb.group({title: ['', Validators.required],description: [''],location: ['', Validators.required],startTime: ['', Validators.required],endTime: ['', Validators.required],suggestLocations: [false, Validators.required]});}
- Utilize the 
FormBuilderby callingfb.group()to create aFormGroupsetting it to our 
 Ask