首页 > 解决方案 > 将多个值存储在一个数组中并以表格形式显示

问题描述

我已将多个值推送到 component.ts 文件中名为 MyArrayType 的数组中,但希望将其显示到 component.html 文件中的表格形式中。它们是我可以将其存储到变量或某种数据绑定中的一种方式吗?

if(this.disableEveryday == false){
  this.MyArrayType.push(
     this.everydayAllFromValue,
     this.everydayBreakfastFromValue,
     this.everydayDinnerFromValue,
     this.everydayLunchFromValue)
}
else{
  this.MyArrayType.push(
      this.mondayAllFromValue,
      this.mondayBreakfastFromValue,
      this.mondayDinnerFromValue,
      this.mondayLunchFromValue,
      this.tuesdayAllFromValue,
      this.tuesdayBreakfastFromValue,
      this.tuesdayDinnerFromValue,
      this.tuesdayLunchFromValue,
      this.wednesdayAllFromValue,
      this.wednesdayBreakfastFromValue,
      this.wednesdayDinnerFromValue,
      this.wednesdayLunchFromValue,
      this.thrusdayAllFromValue,
      this.thrusdayBreakfastFromValue,
      this.thrusdayLunchFromValue,
      this.thrusdayDinnerFromValue,
      this.fridayAllFromValue,
      this.fridayBreakfastFromValue,
      this.fridayLunchFromValue,
      this.fridayDinnerFromValue,
      this.saturdayAllFromValue,
      this.saturdayBreakfastFromValue,
      this.saturdayLunchFromValue,
      this.saturdayDinnerFromValue,
      this.sundayAllFromValue,
      this.sundayBreakfastFromValue,
      this.sundayLunchFromValue,
      this.sundayDinnerFromValue)
}

标签: angularangular6

解决方案


由于很难解释您的问题,但这是以表格形式显示数据的代码 -

   <table>
        <tbody *ngFor="let element of MyArrayType; let j=index">
            <tr>
              <td>{{element}}</td>
            </tr>
          </tbody>
    </table>

推荐阅读