From 9b37f45dd4ba47966a5273aace373f0a5fc6627f Mon Sep 17 00:00:00 2001 From: Tomasz Bak Date: Sat, 8 Oct 2016 21:07:28 +0200 Subject: [PATCH] Add fieldReset parameters (#109) * Fix #9 Can't upload the same file twice --- README.md | 2 ++ src/directives/ng-file-select.ts | 3 +++ src/services/ng2-uploader.ts | 2 ++ 3 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 68c84a72..51cd235c 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ npm install ng2-uploader --save | calculateSpeed | true/false | | data | { userId: 12, isAdmin: true } | | customHeaders | { 'custom-header': 'value' } | +| fieldName | 'user[avatar]' +| fieldReset | true/false | authToken | 012313asdadklj123123 | | authTokenPrefix | 'Bearer' (default) | diff --git a/src/directives/ng-file-select.ts b/src/directives/ng-file-select.ts index 26144f11..e0505737 100644 --- a/src/directives/ng-file-select.ts +++ b/src/directives/ng-file-select.ts @@ -42,6 +42,9 @@ export class NgFileSelectDirective { this.onUpload.emit(data); if (data.done) { this.files = this.files.filter(f => f.name !== data.originalName); + if (this.uploader.fieldReset) { + this.el.nativeElement.value = ''; + } } }); diff --git a/src/services/ng2-uploader.ts b/src/services/ng2-uploader.ts index b81bf515..34b60067 100644 --- a/src/services/ng2-uploader.ts +++ b/src/services/ng2-uploader.ts @@ -78,6 +78,7 @@ export class Ng2Uploader { authTokenPrefix: string = 'Bearer'; authToken: string = undefined; fieldName: string = 'file'; + fieldReset: boolean = true; previewUrl: boolean = false; calculateSpeed: boolean = false; _queue: any[] = []; @@ -99,6 +100,7 @@ export class Ng2Uploader { this.authTokenPrefix = options.authTokenPrefix != null ? options.authTokenPrefix : this.authTokenPrefix; this.authToken = options.authToken != null ? options.authToken : this.authToken; this.fieldName = options.fieldName != null ? options.fieldName : this.fieldName; + this.fieldReset = options.fieldReset != null ? options.fieldReset : this.fieldReset; this.previewUrl = options.previewUrl != null ? options.previewUrl : this.previewUrl; this.calculateSpeed = options.calculateSpeed != null ? options.calculateSpeed : this.calculateSpeed; if (!this.multiple) {