需要在容器元素上添加“cdkDropList”指令并设置“cdkDropListOrientation”属性。代码示例:
HTML部分:
{{media}}
TypeScript部分:
orientation: 'horizontal' | 'vertical' = 'horizontal';
mediaList = ['image1', 'image2', 'video1', 'image3'];
constructor(private changeDetectorRef: ChangeDetectorRef) {}
ngAfterViewInit() {
this.changeDetectorRef.detectChanges();
const queryList = this.dropListContainer.toArray();
queryList.forEach(dropList => {
dropList.dropped.subscribe(event => {
console.log('Item was dropped');
});
});
}