Angular Material Drag and Drop禁用添加拖动侦听器事件

时间:2019-02-22 11:40:54

标签: angular drag-and-drop angular-material angular-directive

我正在使用Angular Material中的拖放事件来实现重叠检测,但是我还需要创建一条指令来监听 drag 事件:

DragDirective:

@Directive({
  selector: '[appDrag]'
})
export class DragDirective {

    constructor(private el: ElementRef, private renderer: Renderer2) {
        this.renderer.setAttribute(el.nativeElement, 'draggable', 'true');
    }

    @HostListener('dragstart', ['$event'])
    public onDragStart(ev: DragEvent) {
        console.log(`onDragStart: `, ev); // doesn't work if cdkDrag attribute is placed on the element
    }

}

HTML:

    <div class="draggable" appDrag cdkDrag *ngFor="let keywordGroupCollection of keywordGroupsSelected; let i = index">
        other elements here
    </div>

0 个答案:

没有答案