当我单击编辑按钮时,我的所有表值都变为输入框?

时间:2017-02-16 10:01:43

标签: html angular typescript

我的HTML包含ng for,我已经获取索引值并使用索引值我可以将我的值输入到输入框中。但是我的所有表列表都显示相同的值并且输入框打开。

<tr *ngFor="let item of items; let i=index">
  <td><input type="checkbox" /></td>
  <td>
    <!-- {{ item.itemName }} -->
    <span *ngIf="!myvar">{{ item.itemName }}</span>
    <span *ngIf="myvar"><input type="text" [(ngModel)]="editUpdate.itemName" name="update.name" (keyup.enter)="UpdateItem()" (keyup.escape)="cancelEditingTodo()"></span>
  </td>
  <td>
    <!-- {{ item.itemType }} -->
    <span *ngIf="!myvar">{{ item.itemType }}</span>
    <span *ngIf="myvar"><input type="text" [(ngModel)]="editUpdate.itemType" name="update.name" (keyup.enter)="UpdateItem()" (keyup.escape)="cancelEditingTodo()"></span>
  </td>
  <td>
    <!-- {{ item.itemDescription }} -->
    <span *ngIf="!myvar">{{ item.itemDescription }}</span>
    <span *ngIf="myvar"><input type="text" [(ngModel)]="editUpdate.itemDescription" name="update.name" (keyup.enter)="UpdateItem()" (keyup.escape)="cancelEditingTodo()"></span>
  </td>
  <td>
    <!-- {{ item.itemCurrentPrice }} -->
    <span *ngIf="!myvar">{{ item.itemCurrentPrice }}</span>
    <span *ngIf="myvar"><input type="text" [(ngModel)]="editUpdate.itemCurrentPrice" name="update.name" (keyup.enter)="UpdateItem()" (keyup.escape)="cancelEditingTodo()"></span>
  </td>
  <td><i class="fa fa-pencil" (click)="editItem(i)" aria-hidden="true"></i></td>
  <td><i class="fa fa-trash" (click)="deleteItem(i)" aria-hidden="true"></i></td>
</tr>

我的ts文件是

editItem(i: number) {
  this.myvar=true;
  this.index=i;
  this.editUpdate=this.items[this.index];
  console.log("edit", this.editUpdate);
}

1 个答案:

答案 0 :(得分:1)

if (i > 0) { isunique = true; for(int j = 0; j < i; j++) { if (validnum[i] == validnum[j]) { isunique = false; System.out.println(validnum[i] + " is not an unique number"); break; } } if(isunique == true) { System.out.println(validnum[i] + " is an unique number"); } } i++; 表达式更改为

*ngIf=