如何有条理地隐藏Angular模板中的值?
我希望将payment.diff
留空,而不是显示"€0.00"。
<tr ng-repeat="payment in payments | filter:search.text | orderBy:sort:reverse"
ng-hide="(search.minAmount != null && search.minAmount > payment.amount) || (search.tenantOnly && !payment.tenant)"
ng-class="{danger: payment.diff > 0}">
<td>{{payment.date | date : "dd MMM yyyy"}}</td>
<td ng-attr-title="{{payment.tenant}}">{{payment.name}}</td>
<td>{{payment.amount | currency: "€ "}}</td>
<td>{{payment.rent | currency: "€ "}}</td>
<td>{{payment.diff | filter : payment.diff != 0 | currency: "€ "}}</td> <!-- How do I hide 0 values? -->
<td>{{payment.desc}}</td>
<td>{{payment.account}}</td>
</tr>
filter : payment.diff != 0
无法正常工作。
答案 0 :(得分:1)
尝试
<td ng-if="payment.diff != 0">{{payment.diff | currency: "€ "}}</td>
<td ng-if="payment.diff == 0"></td>
或者
<td ng-show="payment.diff != 0">{{payment.diff | currency: "€ "}}</td>
<td ng-hide="payment.diff != 0"></td>
第一个优点是只在需要时运行过滤器。