create src/assets/db/clients.json

//add html button

Fetch people
  • {{ clients.name }}

//add to add.component.ts added OnInit to Component import import { ClientService } from './client.service'; //add reg to clients import { HttpClient } from '@angular/common/http';

export class AppComponent { client$ title = 'app'; constructor(private clientService: ClientService){}

fetchClient(){ this.client$ = this.clientService.fetchClient(); }

//add to app.module.ts import httpclient import clientservice //after BrowserModule, add HttpClientModule

add providers: [ClientService]

//new file client.service.ts import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { HttpClient } from '@angular/common/http';

@Injectable() export class ClientService { constructor(private http: HttpClient) {}

   fetchClient(): Observable<Object> {
     return this.http.get('/assets/db/clients.json');
    // return this.http.get('https://codepen.io/jobs.json');
 }

}


125 0 0