File

src/app/directives/dropZone/drop-zone.directive.ts

Metadata

Selector [DropZone]

Index

Outputs
HostListeners

Constructor

constructor()

Outputs

dropped
Type : EventEmitter
hovered
Type : EventEmitter

HostListeners

dragleave
Arguments : '$event'
dragleave($event)
dragover
Arguments : '$event'
dragover($event)
drop
Arguments : '$event'
drop($event)
import { Directive, Output, EventEmitter, HostListener } from '@angular/core';

@Directive({
  selector: '[DropZone]'
})
export class DropZoneDirective {
  @Output() dropped = new EventEmitter<FileList>();
  @Output() hovered = new EventEmitter<boolean>();

  constructor() {}

  @HostListener('drop', ['$event'])
  onDrop($event) {
    $event.preventDefault();
    this.dropped.emit($event.dataTransfer.files);
    this.hovered.emit(false);
  }

  @HostListener('dragover', ['$event'])
  onDragOver($event) {
    $event.preventDefault();
    this.hovered.emit(true);
  }

  @HostListener('dragleave', ['$event'])
  onDragLeave($event) {
    $event.preventDefault();
    this.hovered.emit(false);
  }
}

result-matching ""

    No results matching ""