【问题标题】:Angular ngFor access indexAngular ngFor 访问索引
【发布时间】:2019-02-27 16:13:06
【问题描述】:

如何访问 ngFor 中的索引?

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

谢谢

【问题讨论】:

标签: javascript angular ngfor


【解决方案1】:

你忘记在 ngFor 中添加 * 并且 var name 错误

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

【讨论】:

    【解决方案2】:

    如果你想使用索引打印编号试试这个,它会帮助你。

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

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

    【讨论】:

      猜你喜欢
      • 2018-09-20
      • 1970-01-01
      • 1970-01-01
      • 2017-10-23
      • 2018-02-10
      • 2017-11-24
      • 2019-03-16
      • 2017-03-13
      • 2019-05-11
      相关资源
      最近更新 更多