Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular cdkDropTable错误无法读取属性'_getSiblingContainerFromPosition';未定义的_Angular_Angular7_Mat Table_Angular Cdk - Fatal编程技术网

Angular cdkDropTable错误无法读取属性'_getSiblingContainerFromPosition';未定义的

Angular cdkDropTable错误无法读取属性'_getSiblingContainerFromPosition';未定义的,angular,angular7,mat-table,angular-cdk,Angular,Angular7,Mat Table,Angular Cdk,我使用的cdkDropTable工作正常,除了第一次尝试拖放元素时它不工作,并且控制台上显示以下错误: Uncaught TypeError: Cannot read property '_getSiblingContainerFromPosition' of undefined at DragRef.push../node_modules/@angular/cdk/esm5/drag-drop.es5.js.DragRef._updateActiveDropContainer Unh

我使用的cdkDropTable工作正常,除了第一次尝试拖放元素时它不工作,并且控制台上显示以下错误:

Uncaught TypeError: Cannot read property '_getSiblingContainerFromPosition' of undefined
    at DragRef.push../node_modules/@angular/cdk/esm5/drag-drop.es5.js.DragRef._updateActiveDropContainer

Unhandled Promise rejection: Cannot read property 'getItemIndex' of undefined ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read property 'getItemIndex' of undefined
Uncaught TypeError:无法读取未定义的属性“\u getSiblingContainerFromPosition”
在DragRef.push../node_modules/@angular/cdk/esm5/drag drop.es5.js.DragRef.\u updateActiveDropContainer
未处理的承诺拒绝:无法读取未定义的属性“getItemIndex”;区域:;任务:承诺;值:TypeError:无法读取未定义的属性“getItemIndex”
如果我再次尝试,它将正常工作。
在我的表格中:

<table mat-table #table [dataSource]="dataSource"
cdkDropList
[cdkDropListData]="dataSource.data"
(cdkDropListDropped)="dropTable($event)"
matSort>

在.ts中,dropTable方法是:

dropTable(event: CdkDragDrop<any[]>) {
    const prevIndex = this.dataSource.data.findIndex((d) => d === event.item.data);
    if(event.previousContainer === event.container){
      moveItemInArray(this.dataSource.data, prevIndex, event.currentIndex);
    } else {
      transferArrayItem(event.previousContainer.data, event.container.data, prevIndex, event.currentIndex)
        }
    this.dataSource.data = clonedeep(this.dataSource.data);
    this.tableConfig.tableData = this.dataSource.data;
    this.table.renderRows();
  }
dropTable(事件:CdkDragDrop){
const prevIndex=this.dataSource.data.findIndex((d)=>d==event.item.data);
if(event.previousContainer==event.container){
moveItemInArray(this.dataSource.data、prevIndex、event.currentIndex);
}否则{
transferArrayItem(event.previousContainer.data、event.container.data、PreviousIndex、event.currentIndex)
}
this.dataSource.data=clonedeep(this.dataSource.data);
this.tableConfig.tableData=this.dataSource.data;
this.table.renderRows();
}
我没有找到任何与此相关的答案,除了一个答案,其中一个用户建议在ngOnInit和ngOnChanges中添加
detectChanges
方法。我把它放好了,但没用