Angular 6 Services

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 Angular 6 Services Reviewed by Pakainfo on August 08, 2018 Rating: 5

No comments:

'Heartbroken' family of Nigerian man who died at Calgary airport wants answers

'Heartbroken' family of Nigerian man who died at Calgary airport wants answers Bolante Idowu Alo died following altercation wit...

Powered by Blogger.