如何在不使用ng-template和ng-container的情况下使用* ngFor循环遍历多个tr?

问题描述 投票:0回答:1
  <table>
          <thead>
            <tr>
              <th>Name</th>
              <th>Desc</th>
             </tr>
          </thead>

          <tbody>
            <ng-container *ngFor="let prospect of listData;let rowIndex=index;">
           <tr>
                <td></td>
                <td></td>

            </tr>
            <tr *ngIf="IsOpen">
                <td colspan="2">
                  <div>
                    Edit template
                  </div>
                </td>
              </tr>
           </ng-container>
          </tbody>
        </table>

目前我正在使用ng-container创建连续的行,但是当我在ng-container上使用ng2-dragula时,我遇到了问题。请建议任何其他方法为listData中的每个项创建这两行。

angular2-template
1个回答
0
投票

为这部分制作一个组件:

`<tr>
            <td></td>
            <td></td>

        </tr>
        <tr *ngIf="IsOpen">
            <td colspan="2">
              <div>
                Edit template
              </div>
            </td>
          </tr>

`

然后在上面做ngFor

<tbody> <prospect [isOpen]="IsOpen" *ngFor="let prospect of listData;let rowIndex=index;"> </prospect> </tbody>

你可以根据需要添加输入(例如prospect)和输出。

© www.soinside.com 2019 - 2024. All rights reserved.