在 angular 中进行自定义单击和拖动时如何禁用默认光标样式(文本选择器)?

How to disable default cursor style (text selector) when doing a custom click and drag in angular?

我想在 angularjs 中构建自定义点击和拖动行为时禁用默认光标样式(光标:文本)。我找到了使用 javascript 事件执行此操作的方法,方法是在事件上调用 preventDefault() ,如下所示:

$(element).on('mousedown touchstart', function(event) {
  event.preventDefault();
  mouseDown = true;
});

但是,当使用 angular ng-mousedown 事件或其他 "ng-" 事件时,这是如何工作的?

您可以通过将 $event 作为参数传递给您正在调用的函数来简单地从 ng-mousedown 访问事件,如下所示:

<div ng-mousedown="someFunction($event)">

然后调用preventDefault():

$scope. someFunction = function(event) {
    event.preventDefault();
}