I have one strange problem with the drop event in the AngularJS directive. A listener is added because the console is displayed according to the DOM - element <td class="ng-isolate-scope" droppable="" colspan="2">. When I move to another event - click, for example, everything that works correctly. Here is my html code:
<div ng-app="app">
<div ng-controller="testCtrl">
<table id="testtable">
<tr>
<td colspan="2" droppable>
<a data-ng-repeat="firstLink in first" href="#">
{{firstLink.text}}
</a>
</td>
</tr>
<tr>
<td>
<a data-ng-repeat="secondLink in second" href="#" draggable>
{{secondLink.text}}
</a>
</td>
<td>
<a data-ng-repeat="thirdLink in third" href="#" draggable>
{{thirdLink.text}}
</a>
</td>
</tr>
</table>
</div>
</div>
and here I am the JavaScript:
var app = angular.module('app', []);
app.controller('testCtrl', function ($scope) {
$scope.first = [
{text: 1},
{text: 2},
{text: 3}
];
$scope.second = [
{text: 4},
{text: 5},
{text: 6}
];
$scope.third = [
{text: 7},
{text: 8},
{text: 9}
];
});
app.directive('draggable', function () {
return function(scope, element) {
var el = element[0];
el.draggable = true;
el.addEventListener(
'dragstart',
function(e) {
console.log('dragstart called');
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('Text', 'test test test');
return false;
},
false
);
el.addEventListener(
'dragend',
function(e) {
console.log('dragend called');
e.preventDefault();
return false;
},
false
);
}
});
app.directive('droppable', function () {
return {
scope: {
drop: '&'
},
link: function(scope, element) {
var el = element[0];
console.log(el);
el.addEventListener(
'drop',
function(e) {
console.log('Why im not called?');
return false;
},
false
);
}
}
});
Here is jsFiddle:
http://jsfiddle.net/zono/kyFT8/
What causes this behavior?
Sincerely.
source
share