如何在Angular 7中从http请求中获取正文和标头

时间:2019-01-10 18:04:10

标签: angular7 angular-httpclient

我有我的组成部分:

export class CatalogoComponent implements OnInit {

items: Catalogue[];

constructor(private srvCat: CatalogueService) { }

  ngOnInit() {
    this.srvCat.getItems()
      .subscribe(response => this.items = response);
  }

}

这是我的服务:

export class CatalogueService {

  constructor(private http: HttpClient) { }

  getItems(page?: number): Observable<Catalogue[]> {
    if (!page)
      page = 1;
    return this.http.get<Catalogue[]>('http://localhost:8888/catalogues' + '?page=' + page);
  }

}

如何通过服务从组件中的http客户端响应中获取正文和标头。

0 个答案:

没有答案