Angular හි අන්තිම loop iteration එක

*ngFor සහ @for භාවිතයෙන් අයිතම පුනරාවර්තනය කිරීමේදී, last variable එක භාවිතයෙන් loop එකේ අන්තිම iteration එක තීරණය කළ හැකිය.

*ngFor directive එක සඳහා උදාහරණය:

app/app.component.html<ul>
  <li *ngFor="let el of arr; let last = last">
    {{ last ? 'අන්තිම' : '' }}
    {{ el }}
  </li>
</ul>

@for ගොඩනැගීම සඳහා උදාහරණය:

app/app.component.html<ul>
  @for (el of arr; track $index) {
    <li>
      {{ $last ? 'අන්තිම' : '' }}
      {{ el }}
    </li>
  }
</ul>
Задание 1

array එක දී ඇත:

app/app.component.tsexport class AppComponent {
  public arr: string[] = ['a', 'b', 'c', 'd'];
}

array එකේ අයිතම ලැයිස්තුවක් ලෙස ul තුළ පෙන්වන්න, අන්තිම li එක රතු පාටට හරවමින්.

Задание 2

array එක දී ඇත:

app/app.component.tsexport class AppComponent {
  public arr: string[] = ['a', 'b', 'c', 'd'];
}

array එකේ අයිතම ලැයිස්තුවක් ලෙස ul තුළ පෙන්වන්න, පළමු li එක රතු පාටට හරවමින්, අන්තිම එක - කොළ පාටට හරවමින්.