类型的参数不能分配给类型的参数' cdkdragmove< any gt;'
我试图获取可拖动元素移动时的位置,但找不到任何与 CdkDragMove 配合使用的属性。
HTML 模板
<div
cdkDropList
[cdkDropListData]="day.lunch"
[cdkDropListConnectedTo]="dropTargetIds"
class="example-list"
(cdkDropListDropped)="drop($event)"
(cdkDragMoved)="dragMoved($event)" // <--- Error (see below)
>
//Actual content
</div>
TypeScript
dragMoved(event:CdkDragMove<any>){
// get PosX & PosY
}
drop(event: CdkDragDrop<Recipe[]>) {
// other stuff
}
我收到此错误:
“Event”类型的参数不可分配给类型的参数 'CdkDragMove'。类型“事件”缺少以下属性 来自类型“CdkDragMove”:源、pointerPosition、事件、 距离,三角洲
我也尝试过使用 DragMoved 而不是 $event 但后来我得到了这个
类型参数'(event: CdkDragMove) => void' 不可赋值 到“CdkDragMove”类型的参数。输入 '(事件: CdkDragMove) => void' 缺少以下属性 输入“CdkDragMove”:源、指针位置、事件、距离、 德尔塔
我无法理解这个问题,因为该事件正在处理 drop 函数。 有什么想法吗?
I'm trying to get the position of a draggable element as it's moved around, but I can't find any attribute that works with CdkDragMove.
HTML Template
<div
cdkDropList
[cdkDropListData]="day.lunch"
[cdkDropListConnectedTo]="dropTargetIds"
class="example-list"
(cdkDropListDropped)="drop($event)"
(cdkDragMoved)="dragMoved($event)" // <--- Error (see below)
>
//Actual content
</div>
TypeScript
dragMoved(event:CdkDragMove<any>){
// get PosX & PosY
}
drop(event: CdkDragDrop<Recipe[]>) {
// other stuff
}
I get this error:
Argument of type 'Event' is not assignable to parameter of type
'CdkDragMove'. Type 'Event' is missing the following properties
from type 'CdkDragMove': source, pointerPosition, event,
distance, deltangtsc
I also tried with dragMoved instead of $event but then I get this
Argument of type '(event: CdkDragMove) => void' is not assignable
to parameter of type 'CdkDragMove'. Type '(event:
CdkDragMove) => void' is missing the following properties from
type 'CdkDragMove': source, pointerPosition, event, distance,
delta
I can't get my head around this, 'cause the event is working on the drop function instead.
Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当我无法将
DragDropModule
导入到我的模块中时,出现此错误。I got this error when I had failed to import the
DragDropModule
into my module.解决
我发现
(cdkdragmoved)=“ dragmaved($ event)”
必须放置在cdkdrag
element上,而不是在CDKDROPLIST
元素上。Solved
I found out that the
(cdkDragMoved)="dragMoved($event)"
binding had to be placed at thecdkDrag
element, and not at thecdkDropList
element.正如错误消息所示,您需要添加一个类型来告诉 cdkDragMoved 正在移动什么。就像您已经对 drop 所做的那样:
请参阅文档: https://material.angular.io /cdk/drag-drop/api
As the error message says you need to add a Type to tell the cdkDragMoved what is being moved. Like you already did for drop:
See the Documentation: https://material.angular.io/cdk/drag-drop/api