Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngFor index plus 1 or incresed count by one

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>
like image 752
CommonSenseCode Avatar asked Sep 16 '25 02:09

CommonSenseCode


2 Answers

Why not just do this:

<li *ngFor="let mPrepTasks of project.upcomingMeetingsPrepTask; let i= index;">
   <p>Index {{i + 1}}</p>
</li>
like image 128
Filip Lauc Avatar answered Sep 17 '25 20:09

Filip Lauc


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.

like image 35
Günter Zöchbauer Avatar answered Sep 17 '25 19:09

Günter Zöchbauer