angular 5 个 http post header 响应

angular 5 http post header response

我不确定这是一个错误还是我遗漏了什么,但我正在开发 angular 的最新版本。

我正在向 API 发送请求,而 API return 是空的 body 但我想 return 响应 header回到组件。

下面的代码

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 未定义是我在这里做错了什么还是最新版本中存在已知错误。

代码:

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.