首页 > 解决方案 > 如何显示/隐藏而不是切换图标?

问题描述

我需要显示/隐藏图标,而不是现在切换图标。代码:

                <td *ngIf="isActive !== i" (click)="clickerTrue(set, i)">
                  <img src="https://img.icons8.com/office/30/000000/plus.png"/>
                </td>
                <td *ngIf="isActive === i">  
                  <input type="text" [(ngModel)]="set.note" name="value" class="form-control" /> 
              </td>  

i是索引来自ngFor

  clickerTrue(set, index) { 
    this.isActive = this.isActive === index ? null : index; 
  }

isActive变量第一个值为假。

标签: javascripthtmlangular

解决方案


如果您使用的是 ngFor,为什么要传递对象?

<button *ngFor="let item of items" (click)="toggleActive(item)">click me</button>


toggleActive(item) {
  item.active = !item.active;
}

推荐阅读