Angular4:Http-> HttpClient-requestOptions [英] Angular4: Http -> HttpClient - requestOptions
本文介绍了Angular4:Http-> HttpClient-requestOptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我正在尝试从旧" http迁移到新的httpClient
So, I am trying to migrate from 'old' http to the new httpClient
在http客户端中,我正在服务中使用以下格式:
with the http client I am using this format in my service:
return this.http.get(environment.api+ '.feed.json', requestOptions)
我如何在httpClient中使用它?
how do I use this in httpClient?
尝试了许多thiung ...包括
tried many thiungs... including
return this.http.get(environment.api+ '.feed.json', {params: requestOptions.params})
但出现类型不匹配的情况:(
but getting a type missmatch :(
推荐答案
尝试一下:
const requestOptions = {
params: new HttpParams()
};
requestOptions.params.set('foo', 'bar');
this.http.get(environment.api+ '.feed.json', requestOptions );
这也是指向文档的链接,其中描述了如何使用标头和URL参数的示例进行操作: HttpClient
Here is also the link to the docs describing how to do that with examples for headers and URL Parameters: HttpClient
这篇关于Angular4:Http-> HttpClient-requestOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文