【问题标题】:How to call a method on starting touch/drag in AngularJS如何在AngularJS中调用开始触摸/拖动的方法
【发布时间】:2015-05-30 15:10:15
【问题描述】:

我在 AngularJS 中使用 https://github.com/fatlinesofcode/ngDraggable 进行拖放。 它工作得很好,但是当用户开始拖动时我需要做一些操作。这是myMethod()。我实现了ng-mousedown。在台式机上没有问题,但它不适用于触控设备。

 <div ng-drag="true" ng-drag-data="myObject" ng-mousedown="myMethod()">
    123
 </div>

有什么想法吗?

【问题讨论】:

  • 您尝试使用ngTouchngSwipeLeftngSwipeRight 模块吗?看看here
  • 是的,我试过了。 ngTouch 只有三个指令。 ngClick、ngSwipeLeft 和 ngSwipeRight (docs.angularjs.org/api/ngTouch)。

标签: javascript angularjs drag-and-drop


【解决方案1】:

对于所有有同样问题的人:

我使用了 ngTouch 模块的 $swipe 服务。给定的 div 现在是一个指令。在拖动时调用 myMethod()。

HTML:

<my-directive ng-drag="true" ng-drag-data="myObject" on-drag="myMethod()"></my-directive>

指令:

angular.module('myApp')
.directive('myDirective', ['$swipe',
  function($swipe) {

    return {
      restrict: 'EA',
      scope: {
        onDrag: '&'
      },
      link: function(scope, ele, attrs, ctrl) {
      $swipe.bind(ele, {
          'start': function(coords) {
            scope.onDrag();
          }
      }
    }
}]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多