卡住超过2小时的角CDK拖动 - 无法将项目放在位置
当刚开始进入Angular CDK DragnDrop时,我正在努力完成我的任务。试图拖动图像项目并落入位置时,我得到了无法读取未定义的属性(读取长度')。
不确定这是因为与Angular Dragndrop CDK的不同界面
drop(event: CdkDragDrop<any>) {
if (event.previousContainer === event.container) {
moveItemInArray(
event.container.data,
event.previousIndex,
event.currentIndex
);
} else {
transferArrayItem(
event.previousContainer.data,
event.container.data, // getting undefined here
event.previousIndex,
event.currentIndex
);
console.log(
'transferArrayItem',
event.container.data.colorways
);
const formArry = this.myDivName;
formArry.insert(0, this.fb.control(event.container.data));
}
}
是否事件。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这里,您可以
工作stackblitz
Here you go
Working Stackblitz
理解CDKDROPLIST的最佳方法是忘记CDKDROPLIST。我们需要简单地思考对象的两个数组
CDKDROPLIST只是一个接口,即更改数组元素的位置或将数组的一个元素移至另一个元素。我们可以想象两个简单的输入和三个按钮,第一个按钮互换一个数组中一个元素的位置,另一个按钮在另一个阵列中以及最后一个按钮互换两个阵列的元素
函数moveiteminArray和TransferararayItem只是JavaScript函数。我们可以看到定义 a>我们可以使用是否使用(*)
发出事件的$事件(CDKDroplistDropped)是 cdkdragdrop ,所以我们有
event.container.data我们在[数据]或
CDKDROPLIST
event.container.data 其中 droped
event.previouscontainer.data
so so,您的CDKDROPLIST的数据应为colorways.colorways和imgsource.colorways.colorways.colorways @sameer所说,您需要初始化OBJ imgsource
注意:在.html中使用.html,
以查看“存储” CDKDROPLIST“目标”阵列, ”
(*)例如在要在一个数组中添加元素,在此另一个 cdkdroplist to cdkdroplist to cdkdroplist to cdkdroplist to cdkdroplist “数据”是一个对象的CDKDROPLIST
The best way to understand the cdkDropList is forget the cdkDropList. We need think simply in two arrays of object
The cdkDropList is only an interface to change the position of the elements of the arrays or to move one element of the array to the another one. We can imagine two simple inputs and three buttons, the first buttons interchange the position of one element in one array and in the another one and the last button interchange the elements of the two arrays
The functions moveItemInArray and transferArrayItem are only javascript function. We can see the definition this and we can use or not (*)
The $event that emit an event (cdkDropListDropped) is type of CdkDragDrop, so we have
event.container.data the array we indicate in [data] or the
cdkDropList
event.container.data where is dropped
event.previousContainer.data
So, the data of your cdkDropList should be colorways.colorways and imgSource.colorways as @Sameer says and you need initialize your obj imgSource
NOTE: use in .html
To see the array that "store" the cdkDropList "target"
(*) e.g. in this stackblitz I used the a cdkDropList only to add elements to one array, in this another one drop elements in a CdkDropList to a group of cdkDropList who "data" is an object