Create Event Service
Let's now add a service for creating events and write tests for this service.
We'll cover the following...
Now that the interceptor has been created, we can move on to adding an event-creating service for creating events. First, generate the service.
ng g service services/events/events
Then create a model for events.
ng g interface services/events/event
The first command ng g service services/events/event
creates two files. Below is the expected terminal output.
CREATE src/app/services/events/events.service.spec.ts
CREATE src/app/services/events/events.service.ts
The second command ng g interface services/events/event
creates one file. Below is the expected terminal output.
CREATE src/app/services/events/event.ts
Below is our updated code after running the above two commands. Use this to make further changes in the lesson.
<!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>
Events service
Event model
Update the event model with the properties shown below.
Press + to interact
// src/app/services/event/event.tsexport interface Event {_creator: string;title: string;description?: string;city: string;state: string;startTime: string;endTime: string;suggestLocations: Boolean;members?: Array<any>;displayStart?: string;displayEnd?: string;start?: Date;end?: Date;color?: object;_id?: string;__v?: any;}
Within this model, we have three groups of properties, separated ...