首页 > 解决方案 > 使用单一属性为其他人设置 *ngif = false

问题描述

我必须更新来自 db 的值。当我单击更新按钮时,我正在使用 ngModel 在文本框中设置值。但对于所有其他记录,文本框正在打开。

代码...
HTML

<li  *ngFor="let t of Tutorials ; let i = index">
      {{t.name}} --- {{t.url}}
      <input type="text" [(ngModel)]="tutName" *ngIf="update">
      <input type="text" [(ngModel)]="tutUrl" *ngIf="update">
      <button (click)="updateTut(t)">Update</button>
</li>

读取.ts

    update : boolean = false;
updateTut(tut : Tutorial){
      this.update = !this.update;
      if(this.update){
        this.tutName = tut.name;
        this.tutUrl = tut.url;
        this.update = !this.update;
}

请帮忙

谢谢

标签: angulartypescript

解决方案


在数组对象中有一个属性调用update并更新那个

<input type="text" [(ngModel)]="tutName" *ngIf="t.update">

updateTut(tut : Tutorial){
      tut .update = !tut .update;
      if(this.update){
        this.tutName = tut.name;
        this.tutUrl = tut.url;
        tut.update = !tut.update;
}

推荐阅读