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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章