I'm new to Angular so I decided to try their tutorial, but with some small alterations. Basically I have the following array:
export const HEROES: Hero[] = [
{ id: 11, name: 'Mr. Nice' },
{ id: 12, name: 'Narco' },
{ id: 13, name: 'Bombasto' },
{ id: 14, name: 'Celeritas' },
{ id: 15, name: 'Magneta' },
{ id: 16, name: 'RubberMan' },
{ id: 17, name: 'Dynama' },
{ id: 18, name: 'Dr IQ' },
{ id: 19, name: 'Magma' },
{ id: 20, name: 'Tornado' }
];
And the objective is to list them on screen using *ngFor, so I looked up for some ways to do it and this was the most logical thing for me to do, but it's not working.
<div class="container-fluid bg-secondary padding-sm margin-sm rounded">
<div class="row">
<div *ngFor="let hero of heroes; let index = index">
<div class="col-lg-4 bg-lightblue rounded">
<p class="text-secondary lead">
<span class="text-info text-uppercase lead font-weight-bold">
{{ hero.name}}
</span>
Details
</p>
<p>
<span class="font-weight-bold text-success">
ID:
</span>
{{ hero.id }}
</p>
<p>
<span class="font-weight-bold text-success">
Name:
</span>
{{ hero.name }}
</p>
<label class="font-weight-bold">Change name:
<input [(ngModel)]="hero.name" class="input-md" type="text" placeholder="name">
</label>
</div>
{{ (index + 1) % 3 }}
<div class="row" *ngIf="(index + 1) % 3 == 0"></div>
</div>
</div>
</div>
What I'm attempting to do is to start cycling through the list and when it reaches 3 columns, it adds a row by checking if (index + 1) % 3 equals 0 and continues adding columns on the next row. Right now it's not adding the row when the condition in ngIf is true. What am I doing wrong?