当在 html 元素选择上设置数据源时,复选框的主切换不起作用

Master toggle for checkbox not working when datasource is set on html element selection

我有类似的问题 -

.

但是我没有在那里使用 this.usersdataSource[element.Id] = new MatTableDataSource(res);,而是将其用作 element['usersdataSource'] = new MatTableDataSource(res);

现在在解决方案中我看到使用了 selectionMap -

userSelectionMap: Map<number, SelectionModel<any>> = new Map<number,SelectionModel<any>>();

UserMasterToggle(elementId: number) {
this.isAllUserSelected(elementId)
  ? this.userSelectionMap.get(elementId).clear()
  : this.usersdataSource[elementId].data.forEach(row =>
      this.userSelectionMap.get(elementId).select(row)
    );


 }

  isAllUserSSelected() {
    const numSelected = this.userSSelection.selected.length;
    const numRows = this.leftPanelDataSource.data.length;
    return numSelected == numRows;
  }

当我将数据源值分配给 element['usersdataSource'] = new MatTableDataSource(res);

这样的元素值时,我应该如何使用 userSelectionMap: Map<number, SelectionModel<any>> = new Map<number,SelectionModel<any>>();

I have working stackblitz link for my issue - 谁能帮忙

谢谢

这里是working stackblitz link with your issue fixed.