Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

drop event not working angular 2

Tags:

I'm building upload component in angular 2 and i stumble into problem. (drop) event is not working. This is my implementation

<div
class="input-upload"
*ngIf="status != 'finished'"
(drop)="onDrop($event)"
(dragenter)="dragenter()"
(dragleave)="dragleave()"
(dragover)="dragover()"
[ngClass]="{'drag-over': dragOver | async}"
>

onDrop(event: any) {
event.preventDefault();
event.stopPropagation();
console.log(event)
}

Am i doing something wrong? I even put non existing function in (drop) event and angular is not giving error.

like image 335
Kliment Avatar asked Feb 01 '16 17:02

Kliment


2 Answers

You need to call event.preventDefault() in dragOver(event) to inform the browser that the currently hovered element is a valid drop target.

See also https://developer.mozilla.org/en-US/docs/Web/Events/drop

like image 121
Günter Zöchbauer Avatar answered Sep 24 '22 12:09

Günter Zöchbauer


add this on your dragover and dragend

return false;

@He is already doing what you said

like image 21
Mohy Eldeen Avatar answered Sep 25 '22 12:09

Mohy Eldeen