首页 > 解决方案 > 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?

标签: htmlcssangular

解决方案


问题是索引计数以 开头0,如果乘以 0,则得到 0

所以尝试((j+1) * (i+1)) + j + 1而不是(j*i)+j


推荐阅读