带有方法GET的Angular HttpClient参数不起作用 [英] Angular HttpClient params with method GET do not work

查看:134
本文介绍了带有方法GET的Angular HttpClient参数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用get方法询问您有关参数的问题. 我有这样的东西:

I wanna ask you about params with get method. I have something like this:

    path = 'https://example.com/api';
    const params = new HttpParams();
    params.append('http', 'angular');
    return this.http.get(path, {params: params});

我以为我会有这样的网址:

I thought I would have url like:

www.example.com/api?http=角度

www.example.com/api?http=angular

但是实际上当我在chrome的网络"标签中检查时,请求网址是

but actually when I check that in network tab in chrome, request url is

www.example.com/api

www.example.com/api

当我要获取路径时应该怎么做:www.example.com/api?http=angular 并且可以检查没有chrome的使用方法的请求url吗?我是说在服务中使用该方法的地方?

What should I do when I want to have path: www.example.com/api?http=angular And is it possible to check request url of used method without chrome? I mean in service where I use that method?

推荐答案

append函数调用之后,您需要重新分配.它将返回一个新的 HttpParams 对象.

You need to reassign after the append function call. It returns a new HttpParams object.

const params = new HttpParams().append('http', 'angular');

这是 附加文档 .您可以看到它返回了 HttpParams 实例

append(param: string, value: string): HttpParams

Construct a new body with an appended value for the given parameter name.

并且可以检查没有chrome的使用方法的请求url吗?

And is it possible to check request url of used method without chrome ?

您可以创建 HttpInterceptor 并查看完整的url,将在intercept函数实现中使用.

You can create an HttpInterceptor and see the whole url which will be used in the intercept function implementation.

这篇关于带有方法GET的Angular HttpClient参数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆