我尝试了很多东西,但没有一个有效。因此,发布相同的内容。
这是背景:
我有这个HTML
元素,它将基于ng-repeat
动态创建一个矩形框。在每个Rectangular
框中都有各种 HTML 元素,例如HTML select and input text
etc,用户可以编辑这些字段。我想制作这个矩形框draggable
,以便用户可以移动它。
因此,我写了一个angularjs directive
来做它并且它工作正常但是如果我添加指令,那么框内的select
字段和所有字段rectangular
都不再可编辑,因为它适用draggable directive
于整个rectangular
. 如果我删除此指令,那么它会正常工作。我怎样才能使rectangular
盒子draggable
以及其中的字段是selectable or editable
?
HTML CODE
:
<div ng-repeat="NewField in NewFieldValues">
<div style="width:250px;height:120px;border:1px solid #000;" draggable draggable="true">
<select ng-model="Dynamic.BusinessStep[NewField.ID]" ng-change="BusinessStepChange(NewField.ID,'BusinessStep')" class="form-control">
<option class="dropdown-item" value="" selected> Choose Business Step</option>
<option class="dropdown-item" ng-repeat="businessStep in businessSteps" value="{{ businessStep.value }}"> {{ businessStep.text }} </option>
</select>
<br/>
<input type="text" ng-model="Dynamic.ObjectCount[NewField.ID]" ng-blur="BusinessStepChange(NewField.ID,'EventCount')" placeholder="number of objects" class="form-control"></input>
</div>
<br/>
</div>
Angularjs Directive:
app.directive('draggable', function($document) {
return function(scope, element, attr) {
var startX = 0, startY = 0, x = 0, y = 0;
element.css({
position: 'relative',
border: '1px solid red',
backgroundColor: 'lightgrey',
cursor: 'pointer',
display: 'block'
});
element.on('mousedown', function(event) {
console.log("MOUSE DOWN");
// Prevent default dragging of selected content
event.preventDefault();
startX = event.screenX - x;
startY = event.screenY - y;
$document.on('mousemove', mousemove);
$document.on('mouseup', mouseup);
return true;
});
function mousemove(event) {
console.log("MOUSE MOVE");
y = event.screenY - startY;
x = event.screenX - startX;
element.css({
top : y + 'px',
left : x + 'px'
});
return true;
}
function mouseup() {
$document.off('mousemove', mousemove);
$document.off('mouseup', mouseup);
return true;
}
};
});
我试图改变一些东西,但它们都不起作用。当我尝试将 添加draggable
到矩形框中时,默认情况下其中的字段会获取draggable directive
,因此它们的default
行为被angularjs directive
. 如果有人可以在这里为我提供一些指导,我将不胜感激。