[英]ngIf for closing/opening tag
我有一個表,我正在迭代一個數組。 在某些情況下,我想添加一個額外的<tr>
。 我在尋找這樣的東西:
<table>
<tr *ngFor="let element in array">
<td>
some content
</td>
//Starting block that will only be activated if some variable is true
</tr>
<tr>
<td>
some extra content
</td>
//End of the block that will only be activated if some variable is true
</tr>
</table>
有沒有辦法創建一個可以像這樣包裝它的巨石html?
到目前為止我嘗試過的選項是改變數據結構(數組)所以它包含我正在尋找的元素,但我不滿意只是為了顯示目的而有額外的數據。
這應該做你想要的
<table>
<ng-container *ngFor="let element in array"
<tr>
<td>
some content
</td>
</tr>
<tr *ngIf="someVar">
<td>
some extra content
</td>
</tr>
</ng-container>
</table>
也許最好的選擇是使用ng-repeat 。
ng-repeat示例:
<table ng-controller="myCtrl">
<tr ng-repeat="x in records">
<td>{{x.Name}}</td>
<td>{{x.Country}}</td>
</tr>
</table>
Ng-repeat在您的對象或數組中生成for。
看看這是否可以幫到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.