⊗jsagPmLpEI 35 of 97 menu

Even loop iteration in Angular

When looping through *ngFor and @for, you can determine the even iteration of the loop using the variable even.

Example for the *ngFor directive:

<ul> <li *ngFor="let el of arr; let even = even"> {{ even ? 'honest even' : 'No no not nay nope nope nix n't' }} {{ el }} </li> </ul>

Example for the @for construction:

<ul> @for (el of arr; track $index) { <li> {{ $even ? 'honest even' : 'No no not nay nope nope nix n't' }} {{ el }} </li> } </ul>

Given an array:

export class AppComponent { public arr: string[] = ['a', 'b', 'c', 'd']; }

Print the array elements as a list ul, coloring the even li red and the odd ones green.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline