Merge pull request #786 from albpara/feature/emit-event-when-file-is-selected

Emit event when file is selected
This commit was merged in pull request #786.
This commit is contained in:
Adrian Fâciu
2017-10-07 12:04:31 +03:00
committed by GitHub

View File

@@ -1,4 +1,4 @@
import { Directive, ElementRef, Input, HostListener } from '@angular/core';
import { Directive, EventEmitter, ElementRef, Input, HostListener, Output } from '@angular/core';
import { FileUploader } from './file-uploader.class';
@@ -7,6 +7,7 @@ import { FileUploader } from './file-uploader.class';
@Directive({ selector: '[ng2FileSelect]' })
export class FileSelectDirective {
@Input() public uploader: FileUploader;
@Output() public onFileSelected:EventEmitter<File[]> = new EventEmitter<File[]>();
protected element: ElementRef;
@@ -26,7 +27,7 @@ export class FileSelectDirective {
return !!this.element.nativeElement.attributes.multiple;
}
@HostListener('change')
@HostListener('change', ['$event'])
public onChange(): any {
// let files = this.uploader.isHTML5 ? this.element.nativeElement[0].files : this.element.nativeElement[0];
let files = this.element.nativeElement.files;
@@ -36,6 +37,8 @@ export class FileSelectDirective {
// if(!this.uploader.isHTML5) this.destroy();
this.uploader.addToQueue(files, options, filters);
this.onFileSelected.emit(files);
if (this.isEmptyAfterSelection()) {
// todo
this.element.nativeElement.value = '';