将字符串列表作为查询参数传递给angular中的http.get

时间:2018-05-16 12:40:31

标签: angular http

我的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和as:string [],给我带来同样的错误,有什么想法吗?

2 个答案:

答案 0 :(得分:0)

public ObterSimulacao<T>(inscricao:string,listaDatas: string){
    let params = new HttpParams()
    .append('listDate',listaDatas)
    return this.http.get<T>('http://localhost:50441/api/v1/Movimento/Simulacao/' + inscricao ,{params});
}

使用此

答案 1 :(得分:0)

您需要删除您获得的请求中的括号:

    --- # VMWARE_TOOLS_NOT_RUNNING
- hosts: redhat-vm-guest
  user: ansible-user
  become: true
  become_user: root
  connection: ssh
  gather_facts: false
  tasks:
  - name: check vmware tools is running
    command: /etc/vmware-tools/services.sh status
    register: status
  - name: print status
    debug:
      msg: "{{ status.stdout }}

括号中的所有参数都需要链接到一个键。 例如,如果你想要一个标题,你可以这样做:

public ObterSimulacao<T>(inscricao:string,listaDatas: HttpParams){
    return this.http.get<T>('http://localhost:50441/api/v1/Movimento/Simulacao' + inscricao , listaDatas);
}

希望有所帮助