diff --git a/package.json b/package.json index 0ecb881a..d38f72dd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ngx-uploader", "description": "Angular File Uploader", - "version": "2.0.1", + "version": "2.0.3", "license": "MIT", "main": "index.js", "typings": "index.d.ts", diff --git a/src/directives/ng-file-drop.ts b/src/directives/ng-file-drop.ts index df2d0aaf..3120feb3 100644 --- a/src/directives/ng-file-drop.ts +++ b/src/directives/ng-file-drop.ts @@ -34,7 +34,7 @@ export class NgFileDropDirective implements OnChanges, OnInit { ngOnInit() { this.uploader._emitter.subscribe((data: any) => { this.onUpload.emit(data); - if (data.done) { + if (data.done && this.files && this.files.length) { this.files = this.files.filter(f => f.name !== data.originalName); } }); @@ -98,11 +98,10 @@ export class NgFileDropDirective implements OnChanges, OnInit { @HostListener('change') onChange(): void { this.files = this.el.nativeElement.files; if (!this.files) { - console.log('return'); return; } - if (this.options.filterExtensions && this.options.allowedExtensions) { + if (this.options.filterExtensions && this.options.allowedExtensions && this.files && this.files.length) { this.files = this.files.filter(f => { if (this.options.allowedExtensions.indexOf(f.type) !== -1) { return true; diff --git a/src/directives/ng-file-select.ts b/src/directives/ng-file-select.ts index edb3faa2..40ecdf0d 100644 --- a/src/directives/ng-file-select.ts +++ b/src/directives/ng-file-select.ts @@ -38,7 +38,7 @@ export class NgFileSelectDirective implements OnChanges { this.uploader._emitter.subscribe((data: any) => { this.onUpload.emit(data); - if (data.done) { + if (data.done && this.files && this.files.length) { this.files = this.files.filter(f => f.name !== data.originalName); } }); @@ -63,11 +63,10 @@ export class NgFileSelectDirective implements OnChanges { @HostListener('change') onChange(): void { this.files = this.el.nativeElement.files; if (!this.files) { - console.log('return'); return; } - if (this.options.filterExtensions && this.options.allowedExtensions) { + if (this.options.filterExtensions && this.options.allowedExtensions && this.files && this.files.length) { this.files = this.files.filter(f => { if (this.options.allowedExtensions.indexOf(f.type) !== -1) { return true;