如何从mat-table中取消选择单行

use*_*erx 3 angular-material2 angular angular5

我正在使用选择数据表

取消选择我们使用的所有行:

this.selection.clear();
Run Code Online (Sandbox Code Playgroud)

其中selection是SelectionModel类的对象.现在,如果我想从"组件打字稿代码"后面的代码中删除特定行的选择,那么有什么有用的"angular"语句就像clear()方法一样?

yog*_*rji 6

您可以使用

this.selection.deselect(行)

this.selection.select(行)

使用mat-table取消选择第5行的示例

要执行的功能选择或取消选择特定行.

示例:如果要取消选择3rd行,可以执行以下操作.

this.selection.deselect(this.dataSource.data[2])
Run Code Online (Sandbox Code Playgroud)

这是SelectionModel类的代码