Angular 将字符串列表作为查询参数传递给http.get
我的API中有一个get方法,它接收路径上的ID和日期列表作为查询参数,我的http服务检索我这个错误Angular 将字符串列表作为查询参数传递给http.get,angular,http,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
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...'.
public-obertismulacao(inscricao:string,listaDatas:HttpParams){
返回此.http.get('http://localhost:50441/api/v1/Movimento/Simulacao“+inscricao,{listaDatas});
}
src/app/Data.service.ts(34,95)中的错误:错误TS2345:类型为“{listaDatas:HttpParams;}”的参数不能分配给类型为“{headers?:HttpHeaders |{[header:string]:string | string[]}的参数;观察?:“body”;params?:Ht…”。
对象文字只能指定已知属性,并且类型“{headers?:HttpHeaders{[header:string]:string | string[];};observe?:“body”;params?:Ht…”中不存在“listaDatas”。
我还尝试将listaDatas设置为:any和as:string[],得到相同的错误,有什么想法吗?public-obertismulacao(inscricao:string,listaDatas:string){
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});
}
设params=new-HttpParams()
.append('listDate',listaDatas)
返回此.http.get('http://localhost:50441/api/v1/Movimento/Simulacao/“+inscricao,{params});
}
您需要删除请求中的括号,您将得到:
public ObterSimulacao<T>(inscricao:string,listaDatas: HttpParams){
return this.http.get<T>('http://localhost:50441/api/v1/Movimento/Simulacao' + inscricao , listaDatas);
}
public-obertismulacao(inscricao:string,listaDatas:HttpParams){
返回此.http.get('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});
返回此.http.get('http://localhost:50441/api/v1/Movimento/Simulacao“+inscricao,listaDatas,{headers:yourHeader});
希望对您有所帮助您是否尝试返回此.http.get(“”+inscricao,listaDatas);