Skip to content

Commit

Permalink
fix: check on files.length before filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuri committed Dec 28, 2016
1 parent 284a88b commit 2fea156
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 2 additions & 3 deletions src/directives/ng-file-drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/directives/ng-file-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand All @@ -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;
Expand Down

0 comments on commit 2fea156

Please sign in to comment.