使用 ngIf 在 ngFor 循环的开始或结束时运行函数

NgFor 提供了一些可以别名为局部变量的值

  • index - 从 0 开始的可迭代中当前项的位置(变量)
  • first - (boolean)如果当前项是 iterable 中的第一项,则为 true
  • last - (boolean)如果当前项是 iterable 中的最后一项,则为 true
  • even - (boolean)如果当前索引是偶数,则为 true
  • odd - (boolean)如果当前索引是奇数,则为 true
<div *ngFor="let note of csvdata; let i=index; let lastcall=last">
      <h3>{{i}}</h3> <-- to show index position
      <h3>{{note}}</h3>
      <span *ngIf="lastcall">{{anyfunction()}} </span><-- this lastcall boolean value will be true only if this is last in loop
      // anyfunction() will run at the end of loop same way we can do at start
    </div>