i have an issue with displaying data in console. I am trying to retrieve log data in the console but i am getting null without knowing what the problem is. This is my code:
Service.ts
getItemById(id:number): Observable<any> {
return this.http.get<any>(`${this.API}/${id}`).pipe(catchError(this.handleError
));
}
private handleError(httpErrorResponse:HttpErrorResponse){
if(httpErrorResponse.error instanceof ErrorEvent){
console.error(httpErrorResponse.error.message)
}
return of(null)
}
Component.ts
showItem(id: any) {
this.ItemService.getItemById(id).subscribe((data: any) => {
console.log(data)
this.log = data;
})
}
html button
<td><button class="btn btn-block btn-primary" (click)="showItem(log.id)">{{buttonName}}</button></td>
when i click the button the response is giving 200 in the network section
but the console is returning a null, it does not return the payload.
Any solutions ?