是否可以停止项目排序并在cdkDropList中获取子项的XY坐标?

时间:2019-04-18 15:20:01

标签: angular drag-and-drop angular-cdk angular-material-7

虽然在cdkDropList中添加一个Item时,由于数据排序属性,它位于最左边,但我想在cdkDropList中停止自动排列功能。可行吗如果是,那怎么办?

还可以获取这些子项的XY坐标吗?需要一些帮助。

<div cdkDropList [cdkDropListData]="items" cdkDropListDropped)="drop($event)">
    <div cdkDrag [cdkDragData]="item" *ngFor="let item of items;">
        {{item.name}}
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

您是否对放置事件做出了任何反应?您应该自己在支持数组中移动项目。

根据the official docs改编的示例:

drop(event: CdkDragDrop<string[]>) {
    moveItemInArray(this.items, event.previousIndex, event.currentIndex);
}

您还必须从moveItemInArray导入@angular/cdk/drag-drop