【发布时间】:2020-12-23 10:37:19
【问题描述】:
我已经尝试了好几个小时才能让它工作,但我做不到,我希望你们中的一些人能回答我的问题,因为它必须非常简单,而且我是初学者
我在 Nest 中使用 AngularJs 和 NestJs 使用了 @nestjsx/crud,然后我去了request docs 所以,这里是问题:
这是我的 Angular 服务函数
getProductsOfPiece(pieceId: number): Observable<ProductSimple[]> {
return this.http.get<ProductSimple[]>(
'api/producto/', {
params: {
fields: "id,refFabr,refCliente,descrCorta,imagen",
filter: 'pieza.id||$eq||'+ pieceId
}
}
);
}
这个请求给了我一个400 错误请求,它看起来像这样:
/api/producto/?fields=id,refFabr,refCliente,descrCorta,imagen&filter=pieza.id%257C%257C$eq%257C%257C1
我认为% 和十六进制与 URI 编码有关,并尝试对其进行编码/解码,但没有成功。
我还尝试使用文档中引用的FrontEnd usage 中的@nestjsx/crud-request 的RequestQueryBuilder 类,并将其附加到URL
let queryString = RequestQueryBuilder.create()
.select(["id","refFabr","refCliente","descrCorta","imagen"])
.setFilter({
field: "coleccion.id",
operator: CondOperator.EQUALS,
value: collectionId
}).query();
return this.http.get<ProductSimple[]>(
'api/producto/?'+queryString
);
但结果更糟
/api/producto/?fields=id%2CrefFabr%2CrefCliente%2CdescrCorta%2Cimagen&filter%5B0%5D=pieza.id%7C%7C%24eq%7C%7C1
我不明白我是如何用我的 Postmand 做到这一点的,而且它可以工作!
api/producto/?fields=id,refFabr,refCliente,descrCorta,imagen&filter=coleccion.id||$eq||6
我怎样才能让它工作,我的代码有什么问题?
【问题讨论】:
标签: angularjs parameters request http-get query-parameters