I try to run a drag & drop system on my Angular application, the drag and drop works on an html file with a live-server, but once in my Angular application I can not drag and drop... If you have an idea... Thanks :)
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)">
<img src="https://cdn.arstechnica.net/wp-content/uploads/2016/02/5718897981_10faa45ac3_b-640x624.jpg" draggable="true" ondragstart="drag(event)" id="drag1" width="88" height="31">
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
And the dependencies (in case)
"dependencies": {
"angular": "^1.6.1",
"angular-ui-router": "^0.3.2",
"body-parser": "^1.15.2",
"cors": "^2.8.1",
"express": "^4.13.4",
"method-override": "^2.3.6",
"mongoose": "^4.6.5",
"morgan": "^1.7.0",
"toastr": "^2.1.2"
You're using JS events ( ondrop
, ondragover
) whereas you should implement this the angular way using directives. Here's some examples:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.