您如何有条件地隐藏Angular模板中的值?

时间:2014-11-16 15:05:46

标签: angularjs

如何有条理地隐藏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&nbsp;MMM&nbsp;yyyy"}}</td>
    <td ng-attr-title="{{payment.tenant}}">{{payment.name}}</td>
    <td>{{payment.amount | currency: "€&nbsp;"}}</td>
    <td>{{payment.rent | currency: "€&nbsp;"}}</td>
    <td>{{payment.diff | filter : payment.diff != 0 | currency: "€&nbsp;"}}</td> <!-- How do I hide 0 values? -->
    <td>{{payment.desc}}</td>
    <td>{{payment.account}}</td>
</tr>

filter : payment.diff != 0无法正常工作。

1 个答案:

答案 0 :(得分:1)

尝试

<td ng-if="payment.diff != 0">{{payment.diff | currency: "€&nbsp;"}}</td>
<td ng-if="payment.diff == 0"></td>

或者

<td ng-show="payment.diff != 0">{{payment.diff | currency: "€&nbsp;"}}</td>
<td ng-hide="payment.diff != 0"></td>

第一个优点是只在需要时运行过滤器。