angularjs - 带有 ng-if 的 Angular ng-repeat 不适用于 tr 标签
问题描述
在下面,Div
我使用ng-repeat
一些数据来填充列表。在执行此操作时,我不希望通过使用指令TR
来创建某个标签,如果它符合某个要求,但是无论表达式如何,我都无法正常工作。ng-if
x.Equipment_Cost_Child != 0
ng-if
我怎样才能让它只显示 TR 如果x.Equipment_Cost_Child > 0
?
我已经尝试过“ x.Equipment_Cost_Child > 0
”我还ng-if
直接将 tr 标签而不是 div 标签。
你怎么看?
<div ng-repeat="x in reservationdata" ng-click="customerClickedEvent(x.ID)">
<table class="unit">
Item:{{$index + 1}}
<tr>
<td style="font-weight:bold">Equipment Type: </td>
<td style="font-weight:bold">{{x.EquipmentType}}</td>
</tr>
<tr>
<td style="font-weight:bold" >Equipment Count: </td>
<td style="font-weight:bold">{{x.Equipment_Count}}</td>
</tr>
<tr>
<td>Adult Quantity: </td>
<td>{{x.Equipment_Count_Adult}} Cost @ ${{x.Duration_Cost_Adult}}</td>
</tr>
<div ng-if="x.Equipment_Cost_Child != 0"> //this line doesn't work
<tr>
<td>Child Quantity: </td>
<td>{{x.Equipment_Count_Child}} Cost @ ${{x.Duration_Cost_Child}}</td>
</tr>
</div>
<tr>
<td>Sending Letters: </td>
<td> {{x.Equipment_Form_Status}}</td>
</tr>
<td> Total Cost For Item: </td>
<td> ${{(x.Equipment_Count_Adult * x.Duration_Cost_Adult)+(x.Equipment_Count_Child * x.Duration_Cost_Child)}}
解决方案
在一个标签中同时使用 ng-if 和 ng-repeat:
<tr ng-repeat="feature in features"
ng-if="feature.id === 1" >
</tr>
或者,如果你想有条件地显示一些模板,你可以使用 ng-switch 例如:
<tr
ng-repeat="feature in features"
ng-switch="feature.id" >
<span ng-switch-when="1"></span>
<span ng-switch-when="2"></span>
</tr>
推荐阅读
- python - 如何在pydatatable中加入两个具有不同键列名的数据框?
- powershell - 为什么我找不到在 PowerShell 中定义属性的位置?PSObject 类的源代码在哪里?
- android - 从 Android 上的帧缓冲区读取
- python - eval_training_Data 是否使用完整的训练数据
- c++ - C++:base64 到 PNG 反斜杠问题
- java - 如何在 JavaFX 的文本字段中禁用空格键?
- go - 在第一个空白字符之后,Go 构建未选择 CXX 环境变量
- java - 这个 lambda 表达式中的 imageProxy 参数是如何定义的?
- flutter - 如何使用 Radius CustomPainter 像这个样机一样创建弧
- javascript - Onclick 按钮只能工作一次。div 滑块 scrollIntoView