Wojciech Abacki
Wojciech Abacki

Reputation: 251

SelectedIndex in two dimensional array

<div class="outer" *ngFor="let place of hallPlace; let i = index">
    <div [ngClass]="{'seat-reserve' : selectedIndex === (j*i)+j}" class="inner" *ngFor="let spot of place; let j = index" (click)="setPlace((j*i)+j)">
        <span class="content">{{spot}}</span>
     </div>
</div>

  setPlace(seat) {
    this.selectedIndex = seat;
  }

I have two dimensional array and I want to add class to selected item, now when I click first element add me style to 1 column, and also when i click random element add me style to few elements. How to add style only one element? And It is possible use array of selectedIndex?

Upvotes: 0

Views: 60

Answers (1)

Oleksii Didenko
Oleksii Didenko

Reputation: 69

The problem is that indexes count starts with 0, and if you multiply by 0 you get 0

So try ((j+1) * (i+1)) + j + 1 instead of (j*i)+j

Upvotes: 1

Related Questions