使用ngFor为元素创建唯一的ID

时间:2019-10-04 19:42:40

标签: angular

如果我有这样的手风琴,我将如何使用索引附加到data-targetid 所以不是所有的物品都会一次膨胀和收缩?

<div *ngFor="let item of items; let i = index">
<div class="accordion" id="accordion">
    <div class="card">
      <div class="card-header" id="heading">
        <h2 class="mb-0">
          <div class="btn btn-link collapsed"
          data-toggle="collapse"
          data-target="#collapse"
          id = "card-head"
          aria-expanded="false" aria-controls="collapse">
            {{item.name}} {{item.lastName}}
          </div>
        </h2>
      </div>
      <div id="collapse" class="collapse" aria-labelledby="heading"
      data-parent="#accordion">
        <div class="card-body">
            <p>{{item.content}}</p>
            <button class="btn btn-primary btn-sm">Edit</button>
          </div>
      </div>
    </div>
  </div>
</div>

0 个答案:

没有答案