I am trying to use CdkDragDrop to reorder a list that is hosted in a CdkPortal window and it does not work.
HTML:
<ng-container *cdkPortal>
<ng-content></ng-content>
<hr />
<div cdkDropList class="example-list mt-20"
(cdkDropListDropped)="drop($event)">
<div class="example-box" *ngFor="let movie of movies, index as i"
cdkDrag>
<div class="drag-index" (click)="writelog(movie.name)">{{movie.name}}
</div>
</div>
</div>
<p>{{movie | json}}</p>
Typescript:
import { CdkDragDrop, moveItemInArray } from "@angular/cdk/drag-drop";
import { Component } from "@angular/core";
@Component({
selector: "my-app",
styleUrls: ["./app.component.css"],
templateUrl: "./app.component.html"
})
export class AppComponent {
showPortal = false;
movies = [
{
name: "Episode I - The Phantom Menace",
isDisable: false
},
{
name: "Episode II - Attack of the Clones",
isDisable: false
},
{
name: "Episode III - Revenge of the Sith",
isDisable: false
},
{
name: "Episode IV - A New Hope",
isDisable: false
},
{
name: "Episode V - The Empire Strikes Back",
isDisable: false
},
{
name: "Episode VI - Return of the Jedi",
isDisable: false
}
];
drop(event: CdkDragDrop<string[]>) {
console.log(event.currentIndex + "|||" + event.previousIndex);
moveItemInArray(this.movies, event.previousIndex, event.currentIndex);
}
}
Here is a StackBlitz displaying the problem.
https://stackblitz.com/edit/angular-open-window-g5stn3?file=src%2Fapp%2Fwindow.component.ts
In the page you can see a list...this list is able to be reordered by dragging and dropping.
Now click the "Open me" button and then try to drag to re-order the same list (I couldn't get the styling in it but it is the same code) It will not reorder.