当我在MenuJquery.js:237 Uncaught TypeError: Cannot read property '0' of undefined
at HTMLDivElement.<anonymous> (MenuJquery.js:237)
at HTMLDivElement.dispatch (jquery.min.js:2)
at HTMLDivElement.v.handle (jquery.min.js:2)
内并且四处拖动时,如何防止拖动。
我只希望input
充当pink-meat
。
drag-handle
<div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)">
<div class="example-box" *ngFor="let movie of movies" cdkDrag>
<input [placeholder]="movie" (click)="stopIt($event)" (mousemove)="stopIt($event)">
</div>
</div>
到目前为止,它不起作用:/。
答案 0 :(得分:2)
我会阻止mousedown
而不是click
事件:
(mousedown)="stopIt($event)"
对于移动设备,也许您还会寻找防止touchstart
事件的机会
答案 1 :(得分:0)
我最终使用了指令cdkDropListDisabled
,因为我有一堆应该stop dragging
的元素。
import {Directive, HostListener} from "@angular/core";
@Directive({
selector: "[stopDragging]"
})
export class StopDragging
{
@Input() stopDragging: {bool: boolean};
@HostListener('mouseenter', ['$event'])
public disable(event: any): void
{
debugger;
this.stopDragging.bool = true
}
@HostListener('mouseleave', ['$event'])
public enable(event: any): void
{
debugger;
this.stopDragging.bool = false;
}
}
<ELEMENT ... [cdkDropListDisabled]="dragListDisabled.bool">
<input [stopDragging]="dragListDisabled">
...