ERROR TypeError: this.dataSource.findIndex is not a function

ERROR TypeError: this.dataSource.findIndex is not a function

我有这个:

    removeSelectedRows() {

    this.selection.selected.forEach(item => {
      let index: number = this.dataSource.findIndex(d => d === item);
       console.log(this.dataSource.findIndex(d => d === item));
       this.dataSource.splice(index,1)
       this.dataSource = new MatTableDataSource<Element>(this.dataSource);
}

我想删除选中的行,我在网上找到这段代码,但它给我一个错误:

RefactorComponent.html:12 ERROR TypeError: this.dataSource.findIndex is not a function
    at refactor.component.ts:65
    at Array.forEach (<anonymous>)
    at RefactorComponent.removeSelectedRows (refactor.component.ts:64)
    at Object.eval [as handleEvent] (RefactorComponent.html:12)
    at handleEvent (core.js:43993)
    at callWithDebugContext (core.js:45632)
    at Object.debugHandleEvent [as handleEvent] (core.js:45247)
    at dispatchEvent (core.js:29804)
    at core.js:42925
    at HTMLButtonElement.<anonymous> (platform-browser.js:2668)

我需要您确定所选行的位置,以便将其从数据源中删除。 我正在使用 angular 8.

如果你的数据源是这样定义的

this.dataSource = new MatTableDataSource<Element>(dataArray);

您需要像这样在 this.dataSource.data 上调用方法 findIndex

this.dataSource.data.findIndex(d => d === item);