我使用角度材料在角度2中实现了简单的表格...我已经采用了两个mat-table,其中第一个表格中的选定行在点击移动到表格2 时转移到第二个表格反之亦然点击移至表1
但是当我选择并单击移动到表2 时,我的第一个表中的所有行都会被拼接,我在控制台中收到以下错误,如下所示。
答案 0 :(得分:1)
尝试使用HTML
中的嵌套对象,例如element?.sdeptname
。
这确保即使元素的值为null,有时它也不会在您尝试访问NULL
或undefined
对象时抛出错误。
使用elvis运算符?.
至少可以消除html
<强>更新强>
修正了你的一个功能:
moveToTableTwo() {
console.log(this.dataSource.data)
this.selection.selected.forEach((k,item) => {
this.dataSource.data.splice(this.dataSource.data.indexOf(k),1);
this.checkedDataSource.data.push(k);
});
console.log(this.dataSource.data)
this.dataSource = new MatTableDataSource<Element>(this.dataSource.data);
this.checkedDataSource = new MatTableDataSource<Element>(this.checkedDataSource.data);
}
尝试使用其他功能。
<强>更新强>
你的其他功能应该是这样的:
moveToTableOne() {
this.checkedSelection.selected.forEach((k,item) => {this.checkedDataSource.data.splice(this.checkedDataSource.data.indexOf(k),1);
this.dataSource.data.push(k);
});
this.dataSource = new MatTableDataSource<Element>(this.dataSource.data);
this.checkedDataSource = new MatTableDataSource<Element>(this.checkedDataSource.data);
} }