您可以通过以下方法在Angular 6中动态添加和删除一行包含两个文本框的行:
export class YourComponent {
rows: any[] = [];
constructor() {
// 初始化一行数据
this.addRow();
}
addRow() {
this.rows.push({ text1: '', text2: '' });
}
removeRow(row: any) {
const index = this.rows.indexOf(row);
if (index !== -1) {
this.rows.splice(index, 1);
}
}
}
这样,您就可以在Angular 6中实现在按钮点击时动态添加和删除一行包含两个文本框的行了。