Javascript 在http本机get方法typescript上传递参数数组列表
我正在尝试传递数组列表参数。参数Javascript 在http本机get方法typescript上传递参数数组列表,javascript,angular,typescript,ionic-framework,Javascript,Angular,Typescript,Ionic Framework,我正在尝试传递数组列表参数。参数codeList包含类似数组的 [ { "projCode": "11-1115", "cblTagNo": "571_GE001-RC1" }, { "projCode": "11-1115", "cblTagNo": "571_GE001-S" } ] 但是我面临错误“无效的params对象,需要是带字符串的对象”。我可以知道如何通过obj阵列吗。 这是我的http调用方法 checkCableTagList(
codeList
包含类似数组的
[
{
"projCode": "11-1115",
"cblTagNo": "571_GE001-RC1"
},
{
"projCode": "11-1115",
"cblTagNo": "571_GE001-S"
}
]
但是我面临错误“无效的params对象,需要是带字符串的对象”
。我可以知道如何通过obj阵列吗。
这是我的http调用方法
checkCableTagList(codeList: String[]){
this.http.setDataSerializer('json');
console.log(JSON.stringify(codeList));
return this.http.get('http://hostname/cable/v2/cableschedule/key/', codeList, {});
}
我试过这种方法,但效果不太好
return this.http.get('http://hostname/cable/v2/cableschedule/key/', JSON.stringify(codeList), {});
您可以使用
HttpParams
发送此数组
let httpParams: HttpParams = new HttpParams();
codeList.forEach(code => httpParams = httpParams.append('Projects', code ));
//Http request-
return this.http.get('http://hostname/cable/v2/cableschedule/key/', {
params: HttpParams
}).subscribe(
(response) => //some manipulation with response
);
您是在typescript中使用httpClient还是仅使用http?您的
codeList
是一个对象数组,而不是字符串数组。这会产生将数组添加到checkCableTagList
函数时看到的错误。我更改了post方法,而不是使用get方法。现在可以了。