简体   繁体   中英

Drag and Drop event using angular4 is not working in IE11

I am using a directive to get the files when it is dropped on the HTML element, it is working fine in chrome but it is not working in IE11. 在此处输入图片说明 the following is the code for the drag and drop event import { Directive, HostListener, Output, EventEmitter } from '@angular/core';

@Directive({
  selector: '[appDragDrop]'
})
export class DragDropDirective {

  constructor() { }
  @Output()
  FileDragEvent: EventEmitter<File> = new EventEmitter<File>();

  @HostListener('window:drop', ['$event']) public onDrop(event) {

    event.preventDefault();
    event.stopPropagation();
    if (event.dataTransfer.items[0].type != 'application/vnd.ms-excel') {
      return false;
    }
    let files = event.dataTransfer.files;
    this.FileDragEvent.emit(files);
  }
  @HostListener('window:dragover', ['$event']) public onDragOver(evt) {
    evt.preventDefault();
    evt.stopPropagation();

  }

  @HostListener('window:dragleave', ['$event']) public onDragLeave(evt) {
    evt.preventDefault();
    evt.stopPropagation();

  }
}

intially i was just using like this for the @hostlistener

@HostListener('dragover',

but then i read in some blog which asked me to change it to like this

@HostListener('window:dragover',

I also tried to give min-height to element which has the directive for drag and drop but still i am facing the issue.

the functionality is running smooth in chrome but i am facing issue in IE11

从某些样式的pointer-events: none删除pointer-events: none对于IE 11 pointer-events: none可用,并且一切似乎正常

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM