Click event firing after dragging

后端 未结 2 1795
再見小時候
再見小時候 2021-01-24 05:21

Hey I\'m using Angular material Drag and drop. Everything is working fine but after each drag it triggers the click event and it\'s really annoying. How can I stop this?

相关标签:
2条回答
  • 2021-01-24 05:30

    You can use a boolean to keep a track of this situation:

     var dragging = false;
     (cdkDragStarted): function(event, ui) {
        dragging = true;
        ...your code
     }
    
    (click): function(event) {
        if (!dragging) {
            ...your code
        }
        else {
            dragging = false;
        }
    });
    
    0 讨论(0)
  • 2021-01-24 05:46

    Turning off pointer events for the element while it's being dragged prevents a click event afterwards:

    template:

    <div cdkDrag #draggable="cdkDrag" 
         [class.pointer-events-none]="draggable._dragRef.isDragging()" ...
    

    styles.scss:

    .pointer-events-none {
      pointer-events: none;
    }
    
    0 讨论(0)
提交回复
热议问题