Return local json file from HttpClient

Steps

  • add file.json to src/assets directory
  • use this.http.get('assets/file.json'); in HttpClient
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class ApiService {

  constructor(private http: HttpClient) { }

  getLocalJson() {    
    return this.http.get('assets/file.json');
  }

}