Skip to content

Commit

Permalink
Merge pull request valor-software#786 from albpara/feature/emit-event…
Browse files Browse the repository at this point in the history
…-when-file-is-selected

Emit event when file is selected
  • Loading branch information
Adrian Fâciu authored Oct 7, 2017
2 parents 898f297 + 57b2d07 commit 631b4aa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/file-upload/file-select.directive.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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 = '';
Expand Down

0 comments on commit 631b4aa

Please sign in to comment.