How to pass an array within a query string in HttpClient?

前端 未结 11 879
面向向阳花
面向向阳花 2021-02-02 09:03

This is my array of actors:

[\'Elvis\', \'Jane\', \'Frances\']

How to pass this array within a query strin

11条回答
  •  梦如初夏
    2021-02-02 09:22

    I think the best way is to add them to parameters as a string and have your back-end convert it back to an array or list.

    let actorList = ['Elvis', 'Jane', 'Frances']
    let params = new HttpParams();
    params = params.append('actors', actorList.join(', '));
    this.http.get(url, { params: params });
    

提交回复
热议问题