I am trying to display data from my SQL database on a server. The data is retrieved correctly and all however it is not displaying in my application. If I console.log it displays perfectly in the console.
Interface ts:
export interface IProduct {
productID: string;
productImage: string;
productName: string;
productDescription: string;
productRating: number;
productPrice: number;
}
page.ts:
export class ViewProductPage implements OnInit {
product: IProduct;
constructor(private service: CustomerService) { }
ngOnInit() {
this.service.getProduct().subscribe((data: any) => {
this.product = data;
console.log(this.product);
});
}
}
HTML:
<ion-content color="dark">
<div class="product-image-container">
<div class="product-image-wrapper">
<img [src]="'https://via.placeholder.com/1000'">
</div>
<div class="product-name">
<h1>{{ product.productName }}</h1>
</div>
</div>
<div class="product-description">
<h6>Price:</h6>
<p>{{ product.productPrice }}</p>
<h6>Description:</h6>
<p>{{ product.productDescription }}</p>
</div>
</ion-content>
The error that gets shown in the console is:
ERROR TypeError: can't access property "productName", ctx.product is undefined
Get method:
getProduct(): Observable<IProduct> {
return this.http.get<IProduct>(this.baseURI + 'CustomerOrder/GetProduct/' + this.productID);
}