[英]angular 5 http post header response
I am not sure if this is a bug or i am missing something but i am working on the latest version of angular. 我不确定这是否是错误或缺少什么,但我正在开发最新版本的angular。
I am posting a request to the API, and the API return an empty body but I want to return the response header back to the component. 我向API发布了一个请求,API返回了一个空的正文,但是我想将响应标头返回给该组件。
the code below 下面的代码
add (productslist: number[]):Observable<HttpHeaderResponse> {
return this.http.put<Response>(this.PutUrl, productslist, this.putheader).pipe(
tap(_ => console.log("add")),
// Response(),
catchError(this.handleError<number[]>(`addShoppingCart `)),
map((res:HttpHeaderResponse) =>{
console.log(res);
return res} )
);
}
res
is undefined am I doing something wrong here or is there a known bug in the latest version. res
是未定义的,是我在这里做错了还是最新版本中存在已知错误?
Code: 码:
add (productslist: number[]):Observable<HttpHeaderResponse> {
return this.http.put<Response>(this.PutUrl, productslist, {observe: 'response', headers: this.putheader}).pipe(
tap(_ => console.log("add")),
// Response(),
catchError(this.handleError<number[]>(`addShoppingCart `)),
map((res:HttpHeaderResponse) =>{
console.log(res);
return res} )
);
}
observe : It defines whether we want complete response or body only or events only.
观察 :它定义了我们是只需要完整的响应还是仅是正文或仅是事件。 We need to assign values for observe property such as response for complete response, body for response with body and events for response with events.
我们需要指定用于观察的属性值,如反应完全反应, 身体反应与身体和事件响应的事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.