使用方法GET的Angular HttpClient参数不起作用

时间:2018-01-12 05:08:33

标签: angular http typescript angular-http

我想用get方法向你询问params。 我是这样的:

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

我以为我会像网址一样:

  

www.example.com/api?http=angular

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

  

www.example.com/api

当我想要路径时,我该怎么办:www.example.com/api?http=angular 是否可以检查没有铬的使用方法的请求网址?我的意思是在使用该方法的服务中?

提前致谢

1 个答案:

答案 0 :(得分:2)

您需要在append函数调用后重新分配。它返回一个新的HttpParams对象。

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

这是the documentation of append。您可以看到它返回 HttpParams 实例

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

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

是否可以在没有chrome的情况下检查使用过的方法的请求网址?

您可以创建HttpInterceptor并查看将在intercept函数实现中使用的整个网址。

相关问题