如何在 Angular 上获得 woocommerce 产品评论和星级评分

问题描述 投票:0回答:0

如何整合 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>
angular woocommerce product rating review
© www.soinside.com 2019 - 2024. All rights reserved.