Thanks in advance. Here's the issue:
I'm using Angular Material CDK Drag Drop (version: @angular/ckd: 7.3.7)
The documentation says "Items will automatically rearrange as an element moves."
My question is: How do I prevent items from automatically rearranging as an element moves?
Here is an animated gif of what I don't want. This is a chess board I made and you can see that the "items (chess pieces) are automatically being rearranged as the element (chess piece) moves"
Here is an animated gif of what I want. What I want is for the items (chess pieces) to not be rearranged as the element (chess piece) moves.
Here is a stackblitz with the code
If you want to disable dragging for a particular drag item, you can do so by setting the cdkDragDisabled input on a cdkDrag item. Furthermore, you can disable an entire list using the cdkDropListDisabled input on a cdkDropList or a particular handle via cdkDragHandleDisabled on cdkDragHandle .
To implement drag and drop list you have to include your ngFor repeated section inside a parent div to make that section draggable. This is just a basic structure of how the draggable section should look. Now we have to provide DndList directives to this structure. Basic functioning HTML for drag and drop list.
Install Angular CDK Package for Drag and Drop ts file. import { DragDropModule } from '@angular/cdk/drag-drop'; @NgModule({ declarations: [...], imports: [ DragDropModule ], providers: [...], bootstrap: [...], schemas: [...] })
Since Angular 8, it's possible to disable this behaviour by adding cdkDropListSortingDisabled
just create an empy cdkDragPlaceholder, well, you need enclosed the img in a div
<div class="square"
[ngClass]="{'white': square.row % 2 === square.col %2,
'black': square.row % 2 !== square.col % 2}"
cdkDropList
...>
<div cdkDrag cdkDragBoundary=".board">
<img *ngIf="square.piece"
class="piece"
src="{{square.piece.img()}}"
/>
<!---this is a empty dragPlaceHolder-->
<div *cdkDragPlaceholder></div>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With