如何将 cdkDragDisabled 与 cdkDragStarted 结合起来?
我有一些可拖动的元素。其中一些不可动。如果用户试图移动它们,我想显示一个警报,可以解释为什么您不能移动此元素。
我已经禁用了这些元素的运动,但是我认为CDKDRAGDISABLED会阻止CDKDRAGSTARTED,因为阻力没有“启动”。我以某种方式通过单击元素解决了这一点,但是当您尝试拖动元素时,是否有机会获得警报?
以下是一些最小代码示例:
<ngb-alert #selfClosingAlert *ngIf="movingAlert" type="info" (closed)="movingAlert = ''">{{ movingAlert }}</ngb-alert>
// ...
<ng-container *ngFor="let elem of elements">
<a class="dragelem" cdkDragLockAxis="y" cdkDrag [cdkDragDisabled]="notMovable(elem)" (cdkDragStarted)="changeMovingAlert(elem)">
<div cdkDragHandle><i class="fas fa-grip-vertical"></i></div>
// ...
</a>
</ng-container>
changemovingalert(elem)
仅在不可移动的情况下触发。
如果我将(CDKDRAGSTARTED)更改为(单击)所有内容。但不是它应该做的。
I have some draggable elements. Some of them aren't movable. If the user tries to move them, I want to show an alert, that explains, why you cannot move this element.
I already disabled the movement of those elements, but I think cdkDragDisabled blocks the cdkDragStarted, since the drag doesn't "start". I somehow solved this by clicking on the element, but is there a chance to get the alert, when you try to drag the element?
Here is some minimal code example:
<ngb-alert #selfClosingAlert *ngIf="movingAlert" type="info" (closed)="movingAlert = ''">{{ movingAlert }}</ngb-alert>
// ...
<ng-container *ngFor="let elem of elements">
<a class="dragelem" cdkDragLockAxis="y" cdkDrag [cdkDragDisabled]="notMovable(elem)" (cdkDragStarted)="changeMovingAlert(elem)">
<div cdkDragHandle><i class="fas fa-grip-vertical"></i></div>
// ...
</a>
</ng-container>
The changeMovingAlert(elem)
only triggers if the elem is notMovable.
If I change (cdkDragStarted) to (click) everything works. But not the way it should do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论