0
我有幾個可拖動的面板與鏈接。我想在拖動它們時停止點擊事件。每當我放下瓷磚時,它就會到達地址。我使用ngDraggable.js。我試圖使用e.preventDefault()和e.stopPropagation(),但沒有運氣。如何在ngDraggable angular js中停止點擊事件?
angular.module('ExampleApp', ['ngDraggable']).
controller('MainCtrl', function ($scope) {
$scope.draggableObjects = [
{name: 'one'},
{name: 'two'},
{name: 'three'}
];
$scope.onDropComplete = function (index, obj, evt) {
var otherObj = $scope.draggableObjects[index];
var otherIndex = $scope.draggableObjects.indexOf(obj);
$scope.draggableObjects[index] = obj;
$scope.draggableObjects[otherIndex] = otherObj;
evt.stopPropagation();
evt.preventDefault();
}
});
HTML
<div class="row text-center" ng-controller="MainCtrl">
<ul class="draglist">
<li ng-repeat="obj in draggableObjects" ng-drop="true" ng-drop-success="onDropComplete($index, $data,$event)">
<div ng-drag="true" ng-drag-data="obj" ng-class="obj.name">
{{obj.name}}
</div>
</li>
</ul>
</div>
只是可以肯定,你加入的preventDefault和stopPropagation在onclick/NG - 點擊右鍵? –
感謝羅德里戈。你暗示了答案。我試圖停止瓦片的點擊事件,而不是鏈接。現在我將ng-click設置爲錨標記,並在Angular中執行e.PreventDefault()並且它可以工作 – Octtavius
太棒了!添加了答案,請接受它爲正確 –