here's an approach I have encountered the same problem. I am creating a kanban board with to manage task and to change its status by drag and drop cdk so here's what I did:
html
Tasks To Do
<div class="example-container">
<h2 style="text-align: center;">Tasks In Progress</h2>
<div
cdkDropList
[cdkDropListData]="progresslist"
class="example-list"
(cdkDropListDropped)="drop($event)">
<div (click)=" openDialogAssign(item.taskId,item)" style="background-color: #78C0E0;"class="example-box" *ngFor="let item of progresslist" cdkDrag> <app-boarditem
[item]="item" ></app-boarditem></div>
</div>
</div>
<div class="example-container">
<h2 style="text-align: center;">Tasks To Be Tested</h2>
<div
cdkDropList
[cdkDropListData]="testedslist"
class="example-list"
(cdkDropListDropped)="drop($event)" >
<div (click)=" openDialogAssign(item.taskId,item)" style="background-color: #F8E290;" class="example-box" *ngFor="let item of testedslist" cdkDrag> <app-boarditem
[item]="item" ></app-boarditem></div>
</div>
</div>
<div class="example-container">
<h2 style="text-align: center;">Tasks Done</h2>
<div
cdkDropList
[cdkDropListData]="donelist"
class="example-list"
(cdkDropListDropped)="drop($event)">
<div (click)=" openDialogAssign(item.taskId,item)" style="background-color: rgb(173, 233, 173);" class="example-box" *ngFor="let item of donelist" cdkDrag> <app-boarditem
[item]="item" ></app-boarditem></div>
</div>
</div>
typescript:
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,
event.previousIndex,
event.currentIndex
);
// console.log("ahayhayhy",event.container.id);
console.log( event.container.data[event.currentIndex.valueOf()] );
var taskupdatedStatus:any= event.container.data[event.currentIndex.valueOf()]
// console.log("dattttttttttta",event.container.data);
// x.itemId=index
switch (event.container.id) {
case "cdk-drop-list-0":
{console.log("set to todo");
this.taskservice.changeTaskStatus(taskupdatedStatus.taskId,"todo",taskupdatedStatus).subscribe(res=>{
console.log("task updated to todo",res);
console.log(taskupdatedStatus);
})
}
break;
case "cdk-drop-list-1":
console.log("set to inprogress");
console.log(taskupdatedStatus);
this.taskservice.changeTaskStatus(taskupdatedStatus.taskId,"prog",taskupdatedStatus).subscribe(res=>{
console.log("task updated to prog",res);
console.log(taskupdatedStatus);
})
break;
case "cdk-drop-list-2":
console.log("set to test");
console.log(taskupdatedStatus);
this.taskservice.changeTaskStatus(taskupdatedStatus.taskId,"test",taskupdatedStatus).subscribe(res=>{
console.log("task updated to test",res);
console.log(taskupdatedStatus);
})
break;
case "cdk-drop-list-3":
console.log("set to DONE");
console.log(taskupdatedStatus);
this.taskservice.changeTaskStatus(taskupdatedStatus.taskId,"done",taskupdatedStatus).subscribe(res=>{
console.log("task updated to done",res);
console.log(taskupdatedStatus);
})
break;
default:
console.log("neiver");
break;
}
}
}
this is the line that i implemented to capture the element i just dropped so that i can access its attributs
var taskupdatedStatus:any= event.container.data[event.currentIndex.valueOf()]