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:
your_API_key
Not Specified...
<!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
:-
FormBuilder
is a class that’s used to help us create the various controls, known asFormControls
, within our form. These controls are a part of aFormGroup
which in our case represents our entire form. So our form is composed ofFormControls
that are all a part of aFormGroup
which we create usingFormBuilder
. -
MapsAPILoader
is 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
FormBuilder
andMapsAPILoader
dependencies 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
eventForm
of typeFormGroup
. This is the