Angular 7 Drag&Drop nested lists with native CDK

折月煮酒 提交于 2019-12-04 09:46:06

问题


I am using native Angular 7 Drag&Drop provided by @angular/cdk/drag-drop.

Basically, I just need to create one sortable list inside another one as in the code below:

<div class="external-list" cdkDropList (cdkDropListDropped)="drop1($event)">
  <div class="external-item" cdkDrag *ngFor="let item of items">
    {{item.header}}
    <div class="internal-list" cdkDropList (cdkDropListDropped)="drop2($event)">
      <div class="internal-item" cdkDrag *ngFor="let row of item.rows">
        {{row}}
      </div>
    </div>
  </div>
</div>

This is a very schematic example just to demonstrate the purpose.

The problem is when I try dragging the inner items outer ones are dragged instead.

How can I solve this without resorting to 3rd-party packages?


回答1:


I think you will need to use a drag handle (cdkDragHandle on an element inside cdkDrag), at least for the parent list.

https://material.angular.io/cdk/drag-drop/overview#customizing-the-drag-area-using-a-handle



来源:https://stackoverflow.com/questions/53120167/angular-7-dragdrop-nested-lists-with-native-cdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!