Skip to content

Commit

Permalink
correction UploadFile issue bleenco#282 (bleenco#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
gilsdav authored and jkuri committed Jun 19, 2017
1 parent 115b6bf commit 4a09436
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/ngx-uploader/classes/ngx-uploader.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function humanizeBytes(bytes: number): string {
export class NgUploaderService {
fileList: FileList;
files: UploadFile[];
uploads: { file?: UploadFile, files?: UploadFile[], sub: Subscription }[];
uploads: { file?: UploadFile, files?: UploadFile[], sub: {instance: Subscription} }[];
serviceEvents: EventEmitter<UploadOutput>;

constructor() {
Expand Down Expand Up @@ -110,11 +110,14 @@ export class NgUploaderService {
switch (event.type) {
case 'uploadFile':
this.serviceEvents.emit({ type: 'start', file: event.file });
const sub = this.uploadFile(event.file, event).subscribe(data => {
this.serviceEvents.emit(data);
});

let sub: {instance: Subscription} = {instance: null};

this.uploads.push({ file: event.file, sub: sub });

sub.instance = this.uploadFile(event.file, event).subscribe(data => {
this.serviceEvents.emit(data);
});
break;
case 'uploadAll':
let concurrency = event.concurrency > 0 ? event.concurrency : Number.POSITIVE_INFINITY;
Expand All @@ -140,8 +143,8 @@ export class NgUploaderService {

const index = this.uploads.findIndex(upload => upload.file.id === id);
if (index !== -1) {
if (this.uploads[index].sub) {
this.uploads[index].sub.unsubscribe();
if (this.uploads[index].sub && this.uploads[index].sub.instance) {
this.uploads[index].sub.instance.unsubscribe();
}

this.serviceEvents.emit({ type: 'cancelled', file: this.uploads[index].file });
Expand Down

0 comments on commit 4a09436

Please sign in to comment.