I have a specific template layout that displays only two items in each row as shown below. I want to use the ngFor directive to iterate through them:
<div class="row" *ngFor="let item of cityCodes; let i = index">
<div class="col-6" (click)="cityClick(item.key)">
<div class="img img-1">
</div>
<div class="img-text">
{{cityCodes[i].value}}
</div>
</div>
<div class="col-6" (click)="cityClick(item.key)">
<div class="img img-2">
</div>
<div class="img-text">
{{cityCodes[i+1].value}}
</div>
</div>
</div>
The above code snippet demonstrates my usage of the cityCodes JSON array:
cityCodes=[{12:'patna'},{23:'jaipur'},{21:'Baliya'},{23:'Canugh'}]
Because I'm following a fixed structure of displaying two columns per row, I am accessing the items using cityCodes[i] and cityCodes[i+1] to display images side by side.
After utilizing the [i+1]th item in the first row, the ngFor directive restarts with the same item in the subsequent row. How can I update the index in this scenario?