【发布时间】:2020-05-07 06:52:15
【问题描述】:
我想知道是否可以选择将 if else 语句放入 for 循环中。
如果有机会将此 PHP 代码转换为 angular,我在这里有示例。
PHP 示例
while($row = mysqli_fetch_array($query)) {
$section = $row['name'];
if($section_id == "TEST_ID") {
$section = "APPROVED";
}
else {
$section = "DECLINED";
}
echo $section;
}
角码
注意:这是一个示例代码,仅供参考。
<tr *ngFor="let student of students">
<td>{{ student.student_id | uppercase }}</td>
<td>{{ student.name }}</td>
<td>{{ student.section }}</td>
<td><button class="btn btn-sm btn-primary btn-block" (click)="edit(student)">EDIT</button></td>
<td><button class="btn btn-sm btn-danger btn-block" (click)="delete(student)">DELETE</button</td>
</tr>
我对这个问题进行了研究,但我很困惑,因为我是这个框架的初学者。请帮我解决这个问题,谢谢。
【问题讨论】:
-
我认为您正在寻找 ngIf
-
Angular 中需要
*ngIf指令:angular.io/api/common/NgIf -
是的,Sameer 先生,但我想知道为什么我怎么能把它放在代码中。请帮忙:((
-
这能回答你的问题吗? How to apply filters to *ngFor?
-
这能回答你的问题吗? How to use *ngIf else?
标签: angular ngfor angular-ng-if