angular - cdk drag and drop in a nested situation
问题描述
This is the third question here on SO regarding "cdk dnd" and "nested"!
I did not quite get the hacky suggestion of the other SO question.
So here is a very basic and simple -> STACKBLITZ <- I've created. Everything works fine to the point where I interact with the nested elements inside the container.
When I try to sort just the nested elements, angular tries to sort the nested element with the container itself ... which creates unwanted behavior.
Does anyone have an idea how to solve this? I will further work this one tomorrow.
解决方案
如果您仍在寻找这个问题的答案,您可以使用cdkDragBoundary
来限制可以拖动元素的位置。在您的示例中,它将涉及:
- 向包含嵌套列表的 div 添加一个类
- 将
cdkDragBoundary
属性添加到保存时间段的 div 中,以 1 中添加的类为目标。
容器组件的 HTML 如下所示:
<div style="background-color=pink;">
<div [cdkDropListData]="timePeriods" cdkDropList cdkDropListOrientation="horizontal"
id="containerId" [cdkDropListConnectedTo]="['allDataId']"
(cdkDropListDropped)="drop($event)" class="example-list">
<div class="example-box" cdkDragBoundary=".example-list" *ngFor="let timePeriod of timePeriods" cdkDrag>{{timePeriod}}</div>
</div>
</div>
*编辑了用于定位容器的类
推荐阅读
- stored-procedures - [Amazon](500310) 无效操作:"$$" 处或附近未终止的美元引号字符串
- swift - 结果类型通用参数“T”无法快速推断 5
- angular - 您可以使用不同的 sessionid cookie 发送令牌身份验证吗
- javascript - 屏幕在 CSS 中分成两部分
- django - 翻译默认 Haystack 表单模板的标题
- reactjs - typecrpt 错误:键入 'ITreeNode<{}>[] | undefined' 不可分配给类型 'ITreeNode<{}>[]'
- ionic-framework - Ionic 4 上的 AuthGuard 无法按预期工作
- python - 使用 lambda 或应用于具有列表内容的数据框的多列
- java - 使用 Matlab Java API 依赖构建 Spring-Boot Maven 项目
- node.js - 检查 mongodb 文档是否具有未在模式中定义的属性?