一旦承诺完成,如何在HTML中显示结果

时间:2017-12-09 13:59:40

标签: javascript angular ionic-framework

一旦承诺完成,我想在HTML中显示结果。目前,我就是这样做的:

promoBuyNGetNData = [];//class variable

ngOnInit() {
      Promise.all(this.checkPromoBuyNGetN()).then(values => {
        this.promoBuyNGetNData = values;
      });
}

checkPromoBuyNGetN() {
   var result = [];
   for (let p of this.invoiceProduct) {
      result.push(this.promotionSvc.checkPromoBuyNGetN(this.username, p));
   }
   return result;
}

然后,在HTML中我写这个:

<tr *ngFor="let p of promoBuyNGetNData">
        <td class="name">{{p.productGet}}</td>
        <td class="quantity">{{p.getN}}</td>
        <td class="price">Rp. {{p.price}},00</td>
</tr>

但是,在HTML中它只显示一个空行。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

感谢@manikant评论,我应该这样写:

<tr *ngFor="let p of promoBuyNGetNData[0]">
        <td class="name">{{p.productGet}}</td>
        <td class="quantity">{{p.getN}}</td>
        <td class="price">Rp. {{p.price}},00</td>
        <td class="delete"><ion-icon *ngIf = "isShowInvoice === false" title="delete" name="trash"></ion-icon></td>
</tr>