我有一张桌子,我在一个数组中进行迭代。在某些情况下,我想添加额外的<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?
我到目前为止尝试过的选项是更改数据结构(数组),因此它包含我正在寻找的元素,但我不满意只是为了显示目的而有额外的数据。
答案 0 :(得分:3)
这应该做你想要的事情
<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>
答案 1 :(得分:-3)
也许最好的选择是使用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。
看看这是否可以帮到你。