将多个值存储在数组中并以表格形式显示

时间:2019-06-20 11:38:38

标签: angular angular6

我已将多个值压入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)
}

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

您可以使用* ngFor循环示例:

[{"name":"Ram", "email":"Ram@gmail.com"},  
{"name":"Bob", "email":"bob32@gmail.com"}]  

此处(MyArrayType)这是您的数组名称

如果您的数据(MyArrayType)是类似

的对象类型
<table>
<tbody *ngFor="let data of MyArrayType; let j=index">
    <tr>
      <td>{{data.name}}</td>
      <td>{{data.email}}</td>
    </tr>
 </tbody></table>

比像这样使用它

@JsonInclude(JsonInclude.Include.NON_EMPTY) 

我希望它对您有帮助。...!