When calling a service from a component, I am encountering a 400 bad request error with the following message:
"Invalid data 'undefined' for parameter id"
It's worth noting that the getProduct
method in the API is functioning correctly.
Service.ts
getProduct(ID: number): Observable<any> {
// console.log('ID', ID)
return this.http.get(environment.api+'/products/' + JSON.stringify(ID)) as Observable<Product[]>;
}
component.ts
searchIdAction(id: number){
return this.venteService.getProduct(id).subscribe(
product => {
// console.log('product', product);
this.product = product;
},
)
}
component.html
<clr-input-container *ngIf="options == 1">
<label>Search:</label>
<input clrInput placeholder="search by id..." type="number" (keyup.enter)="searchIdAction(modelProduct.id)"/>
<!-- name="name" [(ngModel)]="modelProduct.id" -->
</clr-input-container>
Your assistance would be greatly appreciated. Thank you in advance