在Angular 2中删除表中的行可以通过以下步骤完成:
rows: any[] = [
{ id: 1, name: 'John' },
{ id: 2, name: 'Jane' },
{ id: 3, name: 'Bob' }
];
<table>
<tr *ngFor="let row of rows">
<td>{{ row.id }}</td>
<td>{{ row.name }}</td>
<td><button (click)="deleteRow(row)">Delete</button></td>
</tr>
</table>
deleteRow(row: any) {
const index = this.rows.indexOf(row);
if (index !== -1) {
this.rows.splice(index, 1);
}
}
这样,当用户点击"Delete"按钮时,表格中对应的行将被删除。
推荐的腾讯云相关产品:腾讯云云服务器(CVM)和腾讯云数据库(TencentDB)。你可以通过以下链接了解更多关于这些产品的信息:
领取专属 10元无门槛券
手把手带您无忧上云