For some reason, I want to apply Angular Material Drag'n'Drop functionality through the DragDrop
service.
As it is written in the doc: https://material.angular.io/cdk/drag-drop/api
DragDrop
Service that allows for drag-and-drop functionality to be attached to DOM elements.
Methods:
createDrag - turns an element into a draggable item
createDropList - turns an element into a drop list.
I was able to add the drag ability to the elements, but I failed with the creation of a Drop List feature:
import {Component, ViewChild, ElementRef, AfterViewInit} from '@angular/core';
import {DragDrop, CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop';
@Component({
selector: 'cdk-drag-drop-sorting-example',
templateUrl: 'cdk-drag-drop-sorting-example.html',
styleUrls: ['cdk-drag-drop-sorting-example.css'],
})
export class CdkDragDropSortingExample implements AfterViewInit {
@ViewChild('dropListArea', {static: false}) dropListArea: ElementRef;
@ViewChild('dragable', {static: false}) dragable: ElementRef;
@ViewChild('dragable2', {static: false}) dragable2: ElementRef;
constructor(private dragDropService: DragDrop) {}
ngAfterViewInit() {
this.dragDropService.createDrag(this.dragable);
this.dragDropService.createDrag(this.dragable2);
this.dragDropService.createDropList(this.dropListArea);
}
}
Here is a live example: https://stackblitz.com/edit/angular-drtbaa?file=app/cdk-drag-drop-sorting-example.ts
I will appreciate any help.