0

Am trying to increment the index value to create a list with numbers 1,2,3,4

<tbody>
    <tr *ngFor="let item of queue.truckQueus; let i = index" [attr.data-index]="i">
      <td>{{i ++ }}</td> //this throws an error
      <td>{{item.truck.reg_no}}</td>
    </tr>
</tbody>

How do i add the numbers from 1

I have also tried adding via

{{i += 1}}

But am always getting an error expression is expected. Where am i going wrong?

3
  • 2
    {{ i + 1 }} ? Commented Aug 1, 2018 at 11:48
  • Hmm I've never tried it before .. but maybe create a function in your .ts file that will do the calculation and returns it? So in the view you would have {{ calc(i) }} Commented Aug 1, 2018 at 11:49
  • 1
    Remove the space and try {{ i++ }} Commented Aug 1, 2018 at 11:49

1 Answer 1

1
<tbody>
    <tr *ngFor="let item of queue.truckQueus; let i = index" [attr.data-index]="i">
      <td>{{i + 1 }}</td>
      <td>{{item.truck.reg_no}}</td>
    </tr>
</tbody>

This must work.

As mentioned in the docs.

JavaScript expressions that have or promote side effects are prohibited, including:

  • assignments (=, +=, -=, ...)
  • new
  • chaining expressions with ; or ,
  • increment and decrement operators (++ and --)

Read Here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.