I'm creating a simple drag&drop application in angular using angular CDK. I just want to drag my box and drop it to another box. But when releasing the dragged box inside the dropped area, I'm getting the error. Kindly help fixing it.
Error I'm getting
Unhandled Promise rejection: Failed to execute 'appendChild' on 'Node': The new child element contains the parent. ; Zone: <root> ; Task: Promise.then ; Value: DOMException: Failed to execute 'appendChild' on 'Node': The new child element contains the parent.
at DragRef._cleanupDragArtifacts (http://localhost:4200/vendor.js:1615:121)
at http://localhost:4200/vendor.js:1471:22
at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:3365:26)
at Zone.run (http://localhost:4200/polyfills.js:3130:43)
at http://localhost:4200/polyfills.js:3861:36
at ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:3397:31)
at Zone.runTask (http://localhost:4200/polyfills.js:3174:47)
at drainMicroTaskQueue (http://localhost:4200/polyfills.js:3565:35)
at ZoneTask.invokeTask [as invoke] (http://localhost:4200/polyfills.js:3475:21)
at invokeTask (http://localhost:4200/polyfills.js:4609:14) Error: Failed to execute 'appendChild' on 'Node': The new child element contains the parent.
at DragRef._cleanupDragArtifacts (http://localhost:4200/vendor.js:1615:121)
at http://localhost:4200/vendor.js:1471:22
at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:3365:26)
at Zone.run (http://localhost:4200/polyfills.js:3130:43)
at http://localhost:4200/polyfills.js:3861:36
at ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:3397:31)
at Zone.runTask (http://localhost:4200/polyfills.js:3174:47)
at drainMicroTaskQueue (http://localhost:4200/polyfills.js:3565:35)
at ZoneTask.invokeTask [as invoke] (http://localhost:4200/polyfills.js:3475:21)
at invokeTask (http://localhost:4200/polyfills.js:4609:14)
api.onUnhandledError @ zone-evergreen.js:651
handleUnhandledRejection @ zone-evergreen.js:675
api.microtaskDrainDone @ zone-evergreen.js:668
drainMicroTaskQueue @ zone-evergreen.js:566
invokeTask @ zone-evergreen.js:469
invokeTask @ zone-evergreen.js:1603
globalZoneAwareCallback @ zone-evergreen.js:1629
And I will paste my code below
My app.component.html
<section>
<div class="wrapper">
<div class="outerBox">
<div class="innerBox" cdkDropList [cdkDropListConnectedTo]="[dropZone]" cdkDrag></div>
</div>
<div class="outerBox" #dropZone="cdkDropList" cdkDropList (cdkDropListDropped)="onItemDrop($event)">
</div>
</div>
</section>
and app.component.ts
import { Component } from '@angular/core';
import {CdkDragDrop, moveItemInArray, transferArrayItem} from '@angular/cdk/drag-drop';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
onItemDrop(event) {
console.log(event);
}
}
and app.component.css file look like
.wrapper {
display: flex;
}
.outerBox {
width: 300px;
height: 500px;
border: 1px solid #333;
padding: 10px;
margin: 10px;
}
.innerBox {
width: 100px;
height: 100px;
background: skyblue;
}
Kindly help in solving the error.
Thanks in advance.