如何在*ngFor中使用*ngIf? [已关闭]

问题描述 投票:0回答:2
angular ngfor angular-ng-if
2个回答
2
投票

花括号不是必需的。如下修改您的代码。 将

<td *ngIf="{{item.status}} == 'present'">
替换为
 <td *ngIf="item.status === 'present'">

<tr *ngFor="let item of attendance; let i = index">
     <th>{{i + 1}}</th>
     <td>{{item.empid}}</td>
     <td>{{item.first_name}} {{item.last_name}}</td>
     <td>{{item.date | date: 'dd-MM-yyyy'}}</td>
     <td *ngIf="item.status === 'present'">
         <span class="badge rounded-pill bg-success">Present</span>
     </td>
</tr>

2
投票

您不需要 HTML 标签内的 {{}} 语法。尝试:

<tr *ngFor="let item of attendance; let i = index">
    <th>{{i + 1}}</th>
    <td>{{item.empid}}</td>
    <td>{{item.first_name}} {{item.last_name}}</td>
    <td>{{item.date | date: 'dd-MM-yyyy'}}</td>
    <td *ngIf="item.status === 'present'">
        <span class="badge rounded-pill bg-success">Present</span>
    </td>
</tr>
© www.soinside.com 2019 - 2024. All rights reserved.