gsk
gsk

Reputation: 2379

calculation with $index in angularjs?

I want to do some arithmetic operation with $index in ng-repeat. The following code is not working:

<tr ng-repeat="item in quotation.items track by $index">
    <td class="text-center"><strong>{{$index++}}</strong></td>
    <td><a href="javascript:void(0);">{{item.item}}</a></td>
    <td>{{item.quantity}}</td>
    <td>{{item.rate}}</td>
    <td>{{item.rate * item.quantity}}</td>
</tr>

How can I solve this?

Upvotes: 0

Views: 273

Answers (1)

Millie Smith
Millie Smith

Reputation: 4604

You need to use + 1. ++ always modifies the variable, and that never works well when you do that on a loop variable.

$index + 1

And this is the correct syntax for the ng-repeat. You don't need a by $index. $index is created automatically.

<tr ng-repeat="item in quotation.items">

Upvotes: 3

Related Questions