I have an image gallery and I intend to drag and drop these images into a drop zone.
I tried to use it in two cases (using the mouse to drag the image and using the cdk drag & drop that allows me to move the image to the drops area as well).
Is there a way to get the object (name, id ...) from the image that is dropped in the drop zone? I try to drag the image to the drop zone and when I release it there, I want to know which image was dropped.
Is there a way to achieve this? Can someone help me?
Thank you very much!
.TS
onFileDropped($event) {
this.prepareFilesList($event);
console.log("evt", $event )
}
fileBrowseHandler(files) {
this.prepareFilesList(files);
}
async prepareFilesList(files: Array<any>) {
}
@HostBinding('class.fileover') fileOver: boolean;
@HostBinding('style.background-color') private background = '#f5fcff'
@Output() fileDropped = new EventEmitter<any>();
// Dragover listener
@HostListener('dragover', ['$event']) onDragOver(evt) {
evt.preventDefault();
evt.stopPropagation();
this.fileOver = true;
this.background = '#9ecbec';
}
// Dragleave listener
@HostListener('dragleave', ['$event']) public onDragLeave(evt) {
evt.preventDefault();
evt.stopPropagation();
this.background = '#f5fcff'
this.fileOver = false;
}
// Drop listener
@HostListener('drop', ['$event']) public ondrop(evt) {
evt.preventDefault();
evt.stopPropagation();
this.background = '#f5fcff'
this.fileOver = false;
let files = evt.dataTransfer.files;
this.fileDropped.emit(files);
}
Using the images (cdkDrag) I was unable to get any events in the drop zone that detect the entry of something.
Using normal images, I was able to execute the function
onFileDropped ($ event) {
this.prepareFilesList ($ event);
console.log ("evt", $ event)
}
but I didn't get results as the image shows.