Aero Wang
Aero Wang

Reputation: 9267

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();

Upvotes: 0

Views: 64

Answers (2)

Huy Chau
Huy Chau

Reputation: 2238

You should use number filter to do it.

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

Hope it can help.

Upvotes: 3

Related Questions