【问题标题】:Angular html table ngfor for rows issue用于行问题的角度 html 表 ngfor
【发布时间】:2020-01-20 17:08:53
【问题描述】:

我有这个 Angular 的 html:

<table>
                <thead>
                    <tr>
                        <th *ngFor="let col of columns">
                            {{col}}
                        </th>
                    </tr>
                    <tr>
                        <th *ngFor="let col of subColumns">
                            {{col}}
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr *ngFor="let priceRow of priceRows">
                    <td *ngFor="let price of priceRow">
                        {{price}}
                    </td>
                </tr>
                </tbody>    
            </table>

这是我正在尝试做行的 priceRows 的内容:

但我在尝试打印表格时得到了空表格。

您在 priceRows 的数组中发现任何错误吗?

Stackblitz 网址:https://angular-bnxfca.stackblitz.io

【问题讨论】:

标签: angular ngfor angular8 angular-ngfor


【解决方案1】:

通过 * ngIf (columns && subColumns && priceRows && priceRow) 为标签表添加验证。

<table *ngIf="colums && subcolums...">

并验证模板上的日期

{{columns|json}}
{{subColumns |json}}

如果模板加载时存在数据,一切都会好的

【讨论】:

    【解决方案2】:

    TS:

    priceRows: any[] = [];
    

    试试这个:

    <table>
        <thead>
            <tr>
                <th *ngFor="let col of columns">
                    {{col}}
                </th>
            </tr>
            <tr>
                <th *ngFor="let col of subColumns">
                    {{col}}
                </th>
            </tr>
        </thead>
        <tbody>
            <tr *ngFor="let price of priceRows">
                <td *ngFor="let item of price">
                    {{item}}
                </td>
            </tr>
        </tbody>
    </table>
    

    Working Stackbiltz Demo

    【讨论】:

      猜你喜欢
      • 2017-06-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-04
      • 1970-01-01
      • 2022-01-24
      • 2019-04-12
      • 2021-01-21
      • 2016-04-23
      相关资源
      最近更新 更多