問題:
I have been looking for a way to pass query parameters into an API call with the new HttpClientModule
's HttpClient
and have yet to find a solution.我一直在尋找一種使用新的HttpClientModule
的HttpClient
將查詢參數傳遞到 API 調用的方法,但尚未找到解決方案。 With the old Http
module you would write something like this.使用舊的Http
模塊,您將編寫類似這樣的內容。
getNamespaceLogs(logNamespace) {
// Setup log namespace query parameter
let params = new URLSearchParams();
params.set('logNamespace', logNamespace);
this._Http.get(`${API_URL}/api/v1/data/logs`, { search: params })
}
This would result in an API call to the following URL:這將導致對以下 URL 的 API 調用:
localhost:3001/api/v1/data/logs?logNamespace=somelogsnamespace
However, the new HttpClient
get()
method doesn't have a search
property, so I am wondering where to pass in the query parameters?但是,新的HttpClient
get()
方法沒有search
屬性,所以我想知道從哪裏傳入查詢參數?
解決方案:
參考一: https://en.stackoom.com/question/34myN參考二: https://stackoom.com/question/34myN