Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set Index for angular2

Tags:

angular

 <template ngFor let-item [ngForOf]="faculytLectureMaster"  >
        <tr *ngIf="item.subjectname != 'Break' && item.facultyname != 'NA'" (click)="OnLectureClick(item,0)" 
             [class.selected]="item === _selectedHero" >
            <td> **set Index number here** </td>
            <td>{{item.lectstart}}-{{item.lectend}}</td>                
            <td>{{item.facultyname}}</td>
            <td>{{item.subjectname}}({{item.subjectcode}})</td>             
            <td>{{item.attendtotal}}</td>
            <td>{{item.present}}</td>
            <td>{{item.absent}}</td>
            <td>{{item.section}}</td>
        </tr>
    </template>

I want to set Index for this template in angular2 like $Index in angular1

I searched I got solutions like *ngFor="let item of _studentList let i=index" which work for normal but in template how to use?

how to do it?

like image 599
User Avatar asked May 12 '26 08:05

User


1 Answers

If you define index like let-i=index, in this case in your ngFor, you could print the index with: {{i}}

Try this one, should work:

 <template ngFor let-item [ngForOf]="faculytLectureMaster" let-i="index" >
        <tr *ngIf="item.subjectname != 'Break' && item.facultyname != 'NA'" (click)="OnLectureClick(item,0)" 
             [class.selected]="item === _selectedHero" >
            <td>{{i}}</td>
            <td>{{item.lectstart}}-{{item.lectend}}</td>                
            <td>{{item.facultyname}}</td>
            <td>{{item.subjectname}}({{item.subjectcode}})</td>             
            <td>{{item.attendtotal}}</td>
            <td>{{item.present}}</td>
            <td>{{item.absent}}</td>
            <td>{{item.section}}</td>
        </tr>
    </template>

More info here

like image 67
AT82 Avatar answered May 15 '26 08:05

AT82



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!