【发布时间】:2018-07-26 19:58:11
【问题描述】:
在 HttpClientModule 中,是否有传递 headers 和 params 来获取请求的方法。
import { HttpHeaders, HttpParams, HttpClient } from @angular/common/http';
const headers = { headers: new HttpHeaders({}) }
let params = new HttpParams({ });
get(url, {params}) // http client get with params
get(url, {headers}); //http client get with headers
我想要像 requestoptions 这样的东西来保存两者或一个语法来做 httpClient 获取发送请求标头和参数。
目前正在构建带有搜索参数和发送标头的完整 url。
【问题讨论】:
-
angular.io/api/common/http/HttpClient#get。您可以将所有这些作为选项对象的一部分传递。
-
无法构建正确的语法,尝试获取 (url, options: { headers: headers, params: params});
标签: angular http-get angular-http angular-http-interceptors angular-httpclient