From the course: Angular: Progressive Web Apps

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Connecting the form with the service

Connecting the form with the service - Angular Tutorial

From the course: Angular: Progressive Web Apps

Connecting the form with the service

- [Instructor] So we need to connect now our coffee component with our data service. So the first step is to add that dependency in our constructor because right now we have only one injectable services here, the geolocation. So we will also need to connect to our data service. So now we are ready to do something on save, but before saving, we need to know if we are editing or inserting a new coffee, because remember that we are reusing the same component here. So a quick way to do that is to create a form type property that will be of type editing or inserting. And we are going to say that we are inserting by default. This is a type that is attached only to two possible values in TypeScript, editing or inserting. We can also create an enum to solve the problem. So then when we are saving now, we can know if we are editing or not based on that flag. So if this.formType is equal to inserting, then I'm going to do…

Contents