我有一个包含数字和文本值的对象。当值为数字时,我想应用 numbers
过滤器。但如果它不是数字,那么将其输出字符串也可以。目前使用 | number
过滤器会格式化数字,但将字符串值留空(毕竟,它们不是数字)。
我猜这可能需要一个自定义过滤器(我还没有制作过)。在进行 ng-repeat 时,是否有一种仅在 HTML 中完成它的方法?
<table>
<tr ng-repeat="(metric, metricData) in data">
<td>{{metric}}</td>
<td>{{metricData | number}}</td>
</tr>
</table>
$scope.data = { name:"this is the name",
score:48
outcome:"as expected",
attendance:820,
total:212.34
};