如何整合 woocomerce api 产品评论和星级评分? 当我运行代码时,它没有显示在 html 上,它说 ERROR TypeError: a.productReviews is undefined.
api.service.ts:
getProductReviews(pid: any) {
const url = `${this.apiUrl}/ecom/wp-json/wc/v3/products/reviews/${pid}?consumer_key=${
this.consumerKey
}&consumer_secret=${this.consumerSecret}`;
console.log(url);
return this.http.get(url);
}
在我的 ts 文件中:
getProductReviews() {
this.apiService.getProductReviews(this.id).subscribe(
(data) => {
this.productReviews = data;
console.log(this.productReviews);
},
(error) => {
this.errorMessage = error.error.message;
console.log(error.error.message, 'error');
}
);
}
在我的html中:
<div class="col-xs-4 col-sm-12 col-md-5 col-lg-5">
<div class="">
<h4 [innerHTML]="productReviews.review"></h4>
</div>
</div>