使用 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>