假设我有以下代码:
<tr ng-repeat="transaction in $data">
<td data-title="'Id'" sortable="id">{{transaction.id}}</td>
<td data-title="'Player'" sortable="playerId">{{transaction.playerId}}</td>
<td data-title="'Type'" sortable="type">{{transaction.type}}</td>
<td data-title="'Date'" sortable="date">{{transaction.date | amDateFormat:'lll'}}</td>
<td data-title="'Provider'" sortable="provider">{{transaction.paymentMethod}}</td>
<td data-title="'Amount'" sortable="amount">{{transaction.amount | currency:'€ '}}</td>
<td data-title="'Code'" sortable="code">{{transaction.code}}</td>
<td data-title="'Status'" sortable="status">{{transaction.status}}</td>
</tr>
对于“transaction.code”,来自服务器的响应是“SRV_DPS”。如何在浏览器中将其显示为“存款”?
答案 0 :(得分:5)
使用自定义过滤器:
JS
.filter('convertCode', function() {
return function(code) {
return (code === 'SRV_DPS') ? 'Deposit' : code;
}
})
查看
{{transaction.code | convertCode}}
答案 1 :(得分:2)
我相信你想要:
<td data-title="'Code'" sortable="code">{{transaction.code == 'SRV_DPS' ? 'Deposit' : 'Other'}}</td>