I am trying to implement nested drag and drop functionality in angular project. For this I am using https://www.npmjs.com/package/ng-drag-drop.
HTML:
<ul>
<li class="parent" draggable [dragScope]="'parentLayout'">Row with Tow Columns</li>
</ul>
<div droppable [dropScope]="'parentLayout'" [dragOverClass]="'drag-target-border'" (onDrop)="onLayoutDrop($event)">
<div class="layout-container">Add Element Container Here</div>
</div>
Inside the 'layout-container
' I want to drag and drop another HTML code. which is:
<div class="container">
<div class="row">
<div class="col-6" droppable [dropScope]="'element'">Column A - Add Element</div>
<div class="col-6" droppable [dropScope]="'element'">Column B - Add Element</div>
</div>
</div>
As you can notice, I want to enable second droppable div inside parent div. This works perfectly when I hardcoded the code. However, I want to fetch the code from database. So I tried using innerHTML, but its not detecting the ng-drag-drop scopes (droppable, [dropScope], etc).
.ts
inner_html: string = '';
// Fetched from database
layout: any = `<div class="container">
<div class="row">
<div class="col-6" droppable [dropScope]="'element'">Column A - Add Element</div>
<div class="col-6" droppable [dropScope]="'element'">Column B - Add Element</div>
</div>
</div>`;
innerElement: string = `<h1>Final Element</h1>`; // This is fetched from database
onLayoutDrop(){
this.inner_html += this.layout;
}
.html
<ul>
<li class="parent" draggable [dragScope]="'parentLayout'">Row with Tow Columns</li>
</ul>
<div droppable [dropScope]="'parentLayout'" [dragOverClass]="'drag-target-border'" (onDrop)="onLayoutDrop($event)">
<div class="layout-container">Add Element Container Here</div>
</div>
<div class="innerhtml" [innerHTML]="layout"></div>