@myog-io/ngx-chunk-file-upload-base
Version:
Angular file upload directives with Chunk Upload
49 lines (38 loc) • 1.09 kB
text/typescript
import {
Directive,
EventEmitter,
ElementRef,
Input,
HostListener,
Output,
} from '@angular/core';
import { FileUploader } from './file-uploader.class';
export class FileSelectDirective {
public uploader: FileUploader;
public onFileSelected: EventEmitter<File[]> = new EventEmitter<File[]>();
protected element: ElementRef;
public constructor(element: ElementRef) {
this.element = element;
}
public getOptions(): any {
return this.uploader.options;
}
public getFilters(): any {
return {};
}
public isEmptyAfterSelection(): boolean {
return !!this.element.nativeElement.attributes.multiple;
}
public onChange(): any {
const files = this.element.nativeElement.files;
const options = this.getOptions();
const filters = this.getFilters();
this.uploader.addToQueue(files, options, filters);
this.onFileSelected.emit(files);
if (this.isEmptyAfterSelection()) {
this.element.nativeElement.value = '';
}
}
}