angular - 防止拖动子元素
问题描述
我有一个包含 4 个子元素的容器。
如果我单击任何节点元素,我想防止拖动。但是如果我从其他任何地方拖动,我想拖动图表容器。
<div class="chart-container" #wrapper cdkDrag>
<ng-container *ngFor="let node of nodes; let i = index">
<div
class="box"
[id]="node.id"
[ngClass]="{ target: node.type === 'target' }"
[style.top.px]="node?.uiPosition?.top || 20"
[style.left.px]="node?.uiPosition?.left || 20"
>
<div class="node">
{{ 'Node' + (i + 1) }}
</div>
</div>
</ng-container>
<div class="example-handle" cdkDragHandle></div>
</div>
.example-handle {
width: 100%;
height: 100%;
background: transparent;
z-index: 5;
}
我添加了一个 z-index 较低的 div 并添加了 cdkDragHandle ,现在我可以拖动容器了。但是有没有更好的方法来处理这个问题?
解决方案
If you want to disable dragging for a particular drag item, you can do so by setting the cdkDragDisabled input on a cdkDrag item. Furthermore, you can disable an entire list using the cdkDropListDisabled input on a cdkDropList or a particular handle via cdkDragHandleDisabled on cdkDragHandle.
这是医生说的。你试过了吗?
推荐阅读
- javascript - 如何立即更新渲染的平面/部分列表项 React Native
- python - ImportError:无法从“tensorflow”导入名称“Session”
- spring - 仅当属性值不是固定值时如何加载 bean
- c++ - clGetProgramBuildInfo 返回空字符串?
- android - Firebase 数据通知无法点击
- react-native - 访问 Header 组件上的 this.props.navigation
- azure-devops - DevOps 服务器激活
- javascript - 使用钩子自动扩展行和子行反应表
- mysql - 如何计算公司不雇用任何人的最长天数
- python - 如何禁用内部 pytest 警告?