访问* ngFor中的项目索引 [英] access to the index of item in *ngFor
本文介绍了访问* ngFor中的项目索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的html页面中有一个循环.代码是:
I have a loop in my html page. The code is:
<li *ngFor="let item of items" style="display: inline;">
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" [routerLink]="['/single-picture/:comment', {comment:item.index} ]">
<img [src]=item.images.low_resolution.url>
</a>
</div>
</li>
在<a class="thumbnail" [routerLink]="['/single-picture/:comment', {comment:item.index} ]">
我想在循环中传递当前项目的索引.
我该怎么办?
推荐答案
<li *ngFor="let item of items;let i=index" style="display: inline;"> //<---added let i=index
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail"
[routerLink]="['/single-picture/:comment', {comment:i} ]"> //<-----changed this line
<img [src]=item.images.low_resolution.url>
</a>
</div>
</li>
这篇关于访问* ngFor中的项目索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文