【发布时间】:2017-08-04 04:41:03
【问题描述】:
我有一个用 HTML 和 AngularJS (Angular 2) 构建的表格。我正在使用 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;
}
【问题讨论】:
标签: javascript html angular