Q:

angular http client

import { HttpClientModule }    from '@angular/common/http';
...
@NgModule({
  imports: [
    HttpClientModule,
  ],
})    
7
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable()
export class ConfigService {
  constructor(private http: HttpClient) { }
}
4
http
  .get<MyJsonData>('/data.json', {observe: 'response'})
  .subscribe(resp => {
    // Here, resp is of type HttpResponse<MyJsonData>.
    // You can inspect its headers:
    console.log(resp.headers.get('X-Custom-Header'));
    // And access the body directly, which is typed as MyJsonData as requested.
    console.log(resp.body.someField);
  });
-2
Here how the request flow while executing angular app:
main.ts  >>   app.Module.ts  >>  app.component.ts  >>  index.html  >>  app.component.html  
-2

New to Communities?

Join the community