Angular 4 HttpClient 查詢參數 - Angular 4 HttpClient Query Parameters

問題:

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.我一直在尋找一種使用新的HttpClientModuleHttpClient將查詢參數傳遞到 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章