【问题标题】:Angular/CSS table formatting. Div objects blocking table formattingAngular/CSS 表格格式。 Div 对象阻止表格格式化
【发布时间】:2019-03-13 00:37:43
【问题描述】:

我在使用这张表时遇到了问题:

  <table style="width: 100%">
    <tr>
      <th>Name</th>
      <th>Ref</th>
      <th>Res</th>
      <th>Pom</th>
    </tr>
    <div *ngFor="let set of ics">
      <tr>
        <td style="column-span: 4">{{set.section}}</td>
      </tr>
      <tr *ngFor="let ic of set.ic">
        <td>{{ic.name}}</td>
        <td>{{ic.ref}}</td>
        <td>{{ic.res}}</td>
        <td>{{ic.pom}}</td>
      </tr>
    </div>
  </table>

我希望它看起来像这样:

| Name             | ref | res | pom |
| section                            |
| d1               | 1   | 2   | 3   |
| d2               | 4   | 5   | 6   | 
| another section                    | 
| d1               | 7   | 8   | 9   |
| d2               | 10  | 11  | 12  |

但它看起来像这样:

| Name             | ref | res | pom |
| section |
| d1      | 1 | 2 | 3 |
| d2      | 4 | 5 | 6 | 
| another section |
| d1              | 7  | 8  | 9  |
| d2              | 10 | 11 | 12 |

我怀疑&lt;div&gt; 对象正在阻止行查看&lt;div&gt; 之外的行。这会阻止他们知道 # 列和宽度之类的东西。我不确定最好的解决方案是什么。

我在&lt;table&gt; 中尝试了*ngFor,它确实有效,但随后我得到每组ics 重复的th 元素,我正在尝试消除混乱。

【问题讨论】:

  • 为什么不使用flexflex-grow

标签: html css angular ngfor


【解决方案1】:

您可以使用&lt;ng-container&gt; HTML 元素,它告诉 Angular 仅在 HTML 中呈现子视图而不是父视图:

<table style="width: 100%">
<tr>
  <th>Name</th>
  <th>Ref</th>
  <th>Res</th>
  <th>Pom</th>
</tr>
<ng-container *ngFor="let set of ics">
  <tr>
    <td style="column-span: 4">{{set.section}}</td>
  </tr>
  <tr *ngFor="let ic of set.ic">
    <td>{{ic.name}}</td>
    <td>{{ic.ref}}</td>
    <td>{{ic.res}}</td>
    <td>{{ic.pom}}</td>
  </tr>
</ng-container>

【讨论】:

  • 这正是我想要的。当时间限制允许时,将标记为已解决。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多