N
N
Nikita Sokolov2019-05-29 16:44:08
JavaScript
Nikita Sokolov, 2019-05-29 16:44:08

Why doesn't preventDefault work for the drop event?

I work on Angular 7 and faced such a problem - I can't implement drag n drop. preventDefault doesn't work and the file just opens in the browser.
In general, the markup in the component is as follows:

<div id="drop-area" (dragover)="preventDefaults($event)" (drop)="handleDrop($event)" (ngClass)="highlight">
...
</div>

And the drop event handler itself:
preventDefaults(e){

    e.preventDefault();
    e.stopPropagation();

}

handleDrop(e){

    preventDefaults(e);
    console.log(e.dataTransfer.files);

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2019-05-29
@wb_by

e.preventDefault() is needed not only on the drop event, but also on the dragover
https://stackoverflow.com/questions/8414154/html5-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question