我有一个内置在HTML和AngularJS(Angular 2)中的表格。我正在使用ngIf指令从单击它的作用域触发可编辑字段。 如果用户单击“编辑”按钮,则只有该行中的所有字段应该变为可编辑。将* ngif标签应用到当前范围/表格行
看到我的代码如下。目前,当用户点击“编辑”按钮时,它将使表中的所有输入字段可编辑。我怎样才能防止这一点?只有“编辑”按钮范围内的行才可编辑。我不知道如何使用AngularJS来完成这个任务。
<tbody>
<tr *ngFor="let location of locations">
<td *ngIf="!editing">{{location.apName}}</td>
<td id="apNameInpit" *ngIf="editing"> <input [(ngModel)]="location.apName" type="text" placeholder="{{location.slackMemberID}}"/></td>
<td *ngIf="!editing">{{location.locationName}}</td>
<td id="locationNameInput" *ngIf="editing"> <input [(ngModel)]="location.locationName" type="text" placeholder="{{location.slackMemberID}}"/></td>
<td *ngIf="!editing">{{location.lat}}</td>
<td id="latInput" *ngIf="editing"> <input [(ngModel)]="location.lat" type="text" placeholder="{{location.slackMemberID}}"/></td>
<td *ngIf="!editing">{{location.long}}</td>
<td id="longInput" *ngIf="editing"> <input [(ngModel)]="location.long" type="text" placeholder="{{location.slackMemberID}}"/></td>
<td *ngIf="!editing">{{location.mac}}</td>
<td id="macInput" *ngIf="editing"> <input [(ngModel)]="location.mac" type="text" placeholder="{{location.slackMemberID}}"/></td>
<td>
<input type="button" *ngIf="!editing" class="btn btn-warning" (click)="engageEditing()" value="Edit" />
<input type="button" *ngIf="editing" class="btn btn-primary" (click)="updateField(location)" value="Update" />
<input type="button" *ngIf="editing" class="btn btn-warning" (click)="cancelEditing()" value="Cancel" />
</td>
</tr>
</tbody>
这是我的location.component.ts代码
engageEditing(){
this.editing = true;
}