angular - 以角度将字符串列表作为查询参数传递给http.get
问题描述
我的 API 中有一个 get 方法,它接收路径上的 ID 和日期列表作为查询参数,我的 http 服务检索到这个错误
public ObterSimulacao<T>(inscricao:string,listaDatas: HttpParams){
return this.http.get<T>('http://localhost:50441/api/v1/Movimento/Simulacao' + inscricao ,{listaDatas});
}
ERROR in src/app/Data.service.ts(34,95): error TS2345: Argument of type '{ listaDatas: HttpParams; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
Object literal may only specify known properties, and 'listaDatas' does not exist in type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
我还尝试将 listaDatas 设置为:any 和:string[],得到同样的错误,有什么想法吗?
解决方案
您需要删除您得到的请求中的括号:
public ObterSimulacao<T>(inscricao:string,listaDatas: HttpParams){
return this.http.get<T>('http://localhost:50441/api/v1/Movimento/Simulacao' + inscricao , listaDatas);
}
括号中的所有参数都需要链接到一个键。例如,如果你想要一个标题,你可以这样做:
return this.http.get<T>('http://localhost:50441/api/v1/Movimento/Simulacao' + inscricao , listaDatas, {headers: yourHeader});
希望能帮助到你
推荐阅读
- artificial-intelligence - 在 FOL 中表示以下句子:
- android - 如果显示软键盘,则完整布局向上移动
- asp.net - 为什么托管网站无法使用 ip 地址工作,但使用 localhost 工作?
- client-server - 如何使用 Vivado 将 Red Pitaya FPGA 与服务器代码连接起来
- javascript - 如何在 ReactJS 的父组件上设置事件监听器?
- windows - JSch - 无法列出某些具有多字节字符的文件路径
- amazon-redshift - 红移优化:减少 i/o 偏差,还是坚持使用连接中使用的 dist 键?
- javascript - 每次动态更改时重置 element.selectedIndex
- c# - 过滤二维数组的技巧
- python - 如何定向 matplotlib ax 对象以沿时间序列线(affine_transform,mtransform)连续绘制?