concept data service in category angular

appears as: data service, The data service
Getting MEAN with Mongo, Express, Angular, and Node.js 2ED

This is an excerpt from Manning's book Getting MEAN with Mongo, Express, Angular, and Node.js 2ED.

The second step is injecting the service into the component, using the constructor as you did inside the data service itself. This time, though, you update the constructor in home-list.component.ts by injecting loc8rDataService of type Loc8rDataService and keeping it private, like this:

In this section, you’ll add the Details page to the Angular SPA. One crucial aspect is retrieving the location ID from the URL parameter to ensure that you get the correct data. Using URL parameters in this way is common practice and is a useful technique to know in any framework. You’ll also have to update the data service to ask the API for specific location details. As you translate the Pug view into an Angular template, you’ll also discover some additional functionality that Angular provides to help you create the various layouts required.

Step 4: Sending the form data to the data service

Your form data is being posted, and you’ve got a data service ready to post it to the API. Now hook these two tasks up. You’ll use the data service as you’ve done before; using this new method is no different.

But first, you need to import the data service into location-details.component.ts and add it to the decorator.

Listing 10.17. Importing and providing the data service to location-details.component.ts
import { Component, Input, OnInit } from '@angular/core';

import { Location } from '../home-list/home-list.component';
import { Loc8rDataService } from '../loc8r-data.service';

@Component({
  selector: 'app-location-details',
  templateUrl: './location-details.component.html',
  styleUrls: ['./location-details.component.css']
})


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":57}]]"}
!@%STYLE%@!