在AngularJs响应设定值视(Setting value depending on respon

2019-10-20 06:04发布

比方说,我有以下代码:

<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”。 如何显示在浏览器的“存款”?

Answer 1:

使用自定义过滤器:

JS

.filter('convertCode', function() {
  return function(code) {
    return (code === 'SRV_DPS') ? 'Deposit' : code;
  }
})

视图

{{transaction.code | convertCode}}

演示



Answer 2:

我相信你想要的:

<td data-title="'Code'" sortable="code">{{transaction.code == 'SRV_DPS' ? 'Deposit' : 'Other'}}</td>


文章来源: Setting value depending on response in AngularJs