如何将多个ngif应用于表上的数据显示?

问题描述 投票:1回答:1

如何对返回到表的数据应用多个* ngIf?

我需要基于多条件* ngIf控制列名,但我不知道使用哪个标记以及在哪里:

*ngIf="coln=repcon.fieldName && repcon.columnType=1" then display data as icon link on field onlineurl
*ngIf="coln=repcon.fieldName && repcon.columnType=2" then make it as hidden field to field onlineurl

我在angular 7应用程序上工作,我显示的动态数据没有固定的标题或内容

 <thead >
                  <tr>
                    <th  *ngFor="let coln of headerCols">


                        {{coln}}

                    </th>


                  </tr>
                </thead>
 <tbody>
                  <ng-container *ngFor="let repcon of ReportControl">
                  <ng-container *ngFor="let repdata of ReportData">
                    <tr *ngFor="let rep of reportdetailslist">

                      <td *ngFor="let coln of headerCols">

                        <span>{{rep[coln]}}</span>
                   // i think here can applied multi ng if but which tag used .
                        </td>

                    </tr>
                  </ng-container>
                </ng-container>

                </tbody>
sample data

ReportId   onlineurl          reportdate
1222       localhost:5000/    12-12-2018
1222       localhost:7000/    12-01-2019
1222       localhost:9000/    12-12-2020
control report
reportid  fieldname   columntype
1222       onlineurl     1
javascript typescript angularjs-directive angular7 angular-components
1个回答
0
投票

鉴于您的条件,您可以嵌套* ngIf:

<td *ngFor="let coln of headerCols">
    <div *ngIf="coln=repcon.fieldName">

        <div *ngIf="repcon.columnType=1">data as icon link</div>

        <div *ngIf="repcon.columnType=2">hidden field</div>
    </div>
</td>

或使用* ngSwitch:

<td *ngFor="let coln of headerCols">
    <div *ngIf="coln=repcon.fieldName" [ngSwitch]="repcon.fieldName">

        <div *ngSwitchCase="1">data as icon link</div>

        <div *ngSwitchCase="2">hidden field</div>

    </div>
</td>
© www.soinside.com 2019 - 2024. All rights reserved.