I have created two divs one containing an image and other is empty. i want to drag and drop that image from one div to another. Here I'm using cdk drag and drop and cdkDragFreeDragPosition property but I'm not satisfied with this as I'm looking for something more like this effect
<div class="example-container">
<h1>From</h1>
<div class="example-list1"
id = "pic1">
<div cdkDrag class="example-box" [cdkDragFreeDragPosition]="dragPosition">
<img width="350px" height="250px" src="https://material.angular.io/assets/img/examples/shiba2.jpg" alt="Photo of a Shiba Inu">
</div>
</div>
</div>
<div class="example-container">
<h1>To</h1>
<div class="example-list"
id = "pic2">
<div cdkDrag class="example-box">
</div>
</div>
</div>
ts:
dragPosition = {x: 0, y: 0};
cdkDrag is not Magic. If you can Drag "something" in a "place" you need use two cdkDropList. When we has two cdkDropList you can think about this as two divs with two arrays
cdk-drag allow interchange the elements from array-one to array-two. Yes, instead make something like
We make dragging
So, you need two
cdkDropList
, inside the cdkDropList you can use a *ngFor in a div, and each div is acdkDrag
, or use an unique element. Again with the example of two divs, we can has something likeBut a
cdkDropList
is not necesary was a list. You can has a cdkDropList with an unique elementIn this case, the interchange is simply