ngFor index plus 1 or incresed count by one
Asked Answered
I

3

4

How to get in angular 2 the index but increased by 1:

<li *ngFor="let mPrepTasks of project.upcomingMeetingsPrepTask; let i= index; let count = i+ 1;">
   <p>Index {{count}}</p>
</li>
Idaliaidalina answered 1/9, 2016 at 15:39 Comment(1)
see this answerClerihew
B
9

Why not just do this:

<li *ngFor="let mPrepTasks of project.upcomingMeetingsPrepTask; let i= index;">
   <p>Index {{i + 1}}</p>
</li>
Bootless answered 1/9, 2016 at 15:41 Comment(0)
S
1

You can't create arbitrary template variables. Inside *ngFor you can only declare variables that are provided by the *ngFor directive.

Either do what @FilipLauc said or do the calculation in the component class instead.

Schizoid answered 1/9, 2016 at 15:42 Comment(0)
Y
0

THIS WORKS

Use single quote. It doesn't remove any data from the array items and at the same time the index starts from 1 and it ends to items.length.

*ngFor="let item of items; let i = 'index+1'";
Yetah answered 8/7, 2022 at 11:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.