首页 > 解决方案 > ng 格式化表格

问题描述

我正在尝试在 Angular 中格式化表格。我有一个名字,姓氏,城市,国家的数据库。我正在尝试以表格格式显示数据。这是我的代码:

<table border="1" style="width:70%">
  <tr bgcolor="lightblue">
    <th style="width:20%">Last Name</th>
    <th style="width:20%">First Name</th>
    <th style="width:40%">Street</th>
    <th style="width:20%">City</th>
  </tr>

  <tbody>
    <span *ngFor="let i of x">
      <tr>
        <td>{{i.lastName}}</td>
        <td>{{i.firstName}}</td>
        <td>{{i.address.street}}</td>
        <td>{{i.address.city}}</td>
      </tr>
    </span>
  </tbody>
</table>

所有表格字段都显示在“姓氏”列下。

附上一张我的桌子的照片。

在此处输入图像描述

标签: angularhtmlhtml-table

解决方案


删除span,它不属于表格(单元格内除外)。将 ngFor 放入tr代替。


推荐阅读