Aero Wang Aero Wang -4 years ago 93
AngularJS Question

Is there a way to process data inside ng-repeat?

For example, if I have:

<tr ng-repeat="x in lists">
<th>{{x[0]}}</th>
<th>{{x[1]}}</th>
<th style="text-align:right">${{x[2]}}</th>
<th>{{x[3]}}</th>
<th>{{x[4]}}</th>
</tr>


I would like the
${{x[2]}}
part to be process and turned into format as
xx.00
with function similar to this:

x[2] = x[2].replace(new RegExp("^(\\d{" + (a.length%3?a.length%3:0) + "})(\\d{3})", "g"), "$1 $2").replace(/(\d{3})+?/gi, "$1 ").trim();

Answer Source

You should use number filter to do it.

To format currency as xx.00, use {{ x[2] | number:2 }}

Hope it can help.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download