Angular JS (angular-ui-tree) ng-click conflict vs drag start event

会有一股神秘感。 提交于 2019-11-30 03:07:00

问题


I am currently using angular-ui-tree library and I am trying to achieve following behavior:

When user just click on 'draggable node' it triggers ng-click function, if user click and start dragging ng-click is ignored and regular drag-n-drop starts.

I have following html structure:

<div ui-tree="rootTree" ng-controller="Controller">
    <div ui-tree-nodes="" ng-model="nodes">
        <div ng-repeat="node in nodes" ui-tree-node="" ng-click="selectNode(node)" >
            <div ui-tree-handle="">
            ...
            </div>
        </div>
    </div>
</div>

Current behavior is that drag-n-drop starts immediately on 'mousedown' and there is no way to distinguish 'click' from attempt to start dragging

Here is the library code which triggers drag-n-drop of the node uiTreeNode.js

var bindDrag = function() {
   element.bind('touchstart mousedown', function (e) {
   if (!scope.$treeScope.multiSelect) {
      dragDelaying = true;
      dragStarted = false;
      dragTimer = $timeout(function() {
         dragStartEvent(e);
         dragDelaying = false;
      },    scope.$treeScope.dragDelay);
   } else {
      toggleSelect(e);
   }
   });
   element.bind('touchend touchcancel mouseup', function() {
      $timeout.cancel(dragTimer);
   });
};

回答1:


I just had the same issue and I solved it by increasing the data-drag-delay to 100, Try:

ui-tree="rootTree" ng-controller="Controller" data-drag-delay="100"




回答2:


It's quite old question, but if you don't want to have delay you can register dropped() callback and execute your click action if index did not change. For example:

dropped: function(event){
    //if element was not moved, use click event
    if(event.source.index == event.dest.index){
        $scope.someAction();
    }
}


来源:https://stackoverflow.com/questions/27088636/angular-js-angular-ui-tree-ng-click-conflict-vs-drag-start-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!