我有一个标准对象,其中一些属性可以为null,如果我不做任何事情,查询字符串包括那些像&p=undefined
这是不可取的,因为在WebApi这些来自as"null"
而不是null
所以在Angular客户端给出这个
return this._http
.get<ExposureDifference[]>(AppSettings.ExposureRunDataQueryString, {params : <any>criteria, withCredentials: true})
.catch<any, ExposureDifference[]>(this._trace.handleError("GET " + AppSettings.ExposureRunDataQueryString + criteria, []))
.finally(() => this.isLoading = false);
我可以将查询字符串作为
http://localhost:63037/api/exposureRuns/data/?id=3&secsymb=undefined&fund=EL&esectype=SWAP_CDS
有没有办法从查询字符串中排除未定义的参数?
你可以试试这个:
this.httpClient.get('../api/path', {
params: Object.entries(queryParameterObject).reduce((queryParams, [key, value]) => queryParams.set(key, value), new HttpParams());
});
它对我有用。