繁体   English   中英

Angular ngFor访问索引

[英]Angular ngFor access index

如何访问ngFor内的索引?

https://stackblitz.com/edit/angular-ekze7q

谢谢

您忘记在ngFor中添加*,并且var名称错误

<p *ngFor="let i of Arr(count); let index = index">
  <button (click)="removeElement(index)">test</button>
</p>

如果要使用索引打印编号,请尝试此操作,它将为您提供帮助。

<ul *ngFor="let item of Array; let i = index">
 <li> {{i+1}}={{item.name}}</li> 
</ul>

供参考: https : //angular.io/api/common/NgForOf

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM