Overload request headers and params with HttpClient get

前端 未结 2 1756
星月不相逢
星月不相逢 2021-01-05 15:55

In HttpClientModule, is there a method to pass headers and params to get request.

   import { HttpHeaders, HttpParams, HttpClient } from @angular/common/http         


        
2条回答
  •  旧巷少年郎
    2021-01-05 16:26

    As of Angular 5.0.0-beta.6 (2017-09-03), you can now pass in both headers and parameters using the below syntax:

    const httpOptions = {
      headers: { 'Content-Type': 'application/json' },
      params: {'include': 'somethingCool'}
    };
    
    this.http.get('http://www.example.org', httpOptions);
    

    Source: https://github.com/angular/angular/pull/18490

提交回复
热议问题