Angular 6 Services
For our users component, we want to fetch a list of users from a public API. To do that, we're going to use the Angular CLI to generate a service for us.An Angular 6 service is useful placing code that's reusable throughout your app's different components.
In the console, type:
> ng generate service data
Open up the new service file: /src/app/data.service.ts:import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class DataService {
constructor() { }
}
It looks similar to a regular component, right? You define your
imports at the top, and your methods and properties in the class that's
exported.The purpose of our service file will be to communicate with an API via the Angular 6 HTTP Client.
Angular 6 Services
Reviewed by Pakainfo
on
August 08, 2018
Rating:
No comments: