Just an update to this, Thierry's answer is still correct, but there has been an update to Angular2 with regards to:
<ul *ngFor="let item of items; let i = index" [attr.data-index]="i">
<li>{{item}}</li>
</ul>
The #i = index
should now be let i = index
EDIT/UPDATE:
The *ngFor
should be on the element you're wanting to foreach, so for this example it should be:
<ul>
<li *ngFor="let item of items; let i = index" [attr.data-index]="i">{{item}}</li>
</ul>
EDIT/UPDATE
Angular 5
<ul>
<li *ngFor="let item of items; index as i" [attr.data-index]="i">{{item}}</li>
</ul>
EDIIT/UPDATE
Angular 7/8
<ul *ngFor="let item of items; index as i">
<li [attr.data-index]="i">{{item}}</li>
</ul>