【发布时间】:2013-06-16 20:42:04
【问题描述】:
我有一个对象,其中包含值的数字和文本的混合。当对象的值是数字时(显然),我想将 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
};
【问题讨论】:
-
您知道,客户过滤器不是一个坏方法......
-
我想不是。我只是还没学会怎么做。也许是我学习的时候了。哈。
标签: javascript html angularjs angularjs-ng-repeat angularjs-filter