Reputation: 980
I am not sure if this is a bug or i am missing something but i am working on the latest version of 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.
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.
Upvotes: 1
Views: 944
Reputation: 4798
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.
Upvotes: 2