feat(package): upgrade to ng v2.3+ (#574)
This commit was merged in pull request #574.
This commit is contained in:
committed by
GitHub
parent
f5b5dc3bd2
commit
3cc6a9946f
46
src/file-upload/file-select.directive.ts
Normal file
46
src/file-upload/file-select.directive.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Directive, ElementRef, Input, HostListener } from '@angular/core';
|
||||
|
||||
import { FileUploader } from './file-uploader.class';
|
||||
|
||||
// todo: filters
|
||||
|
||||
@Directive({selector: '[ng2FileSelect]'})
|
||||
export class FileSelectDirective {
|
||||
@Input() public uploader:FileUploader;
|
||||
|
||||
protected element:ElementRef;
|
||||
|
||||
public constructor(element:ElementRef) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
public getOptions():any {
|
||||
return this.uploader.options;
|
||||
}
|
||||
|
||||
public getFilters():any {
|
||||
return void 0;
|
||||
}
|
||||
|
||||
public isEmptyAfterSelection():boolean {
|
||||
return !!this.element.nativeElement.attributes.multiple;
|
||||
}
|
||||
|
||||
@HostListener('change')
|
||||
public onChange():any {
|
||||
// let files = this.uploader.isHTML5 ? this.element.nativeElement[0].files : this.element.nativeElement[0];
|
||||
let files = this.element.nativeElement.files;
|
||||
let options = this.getOptions();
|
||||
let filters = this.getFilters();
|
||||
|
||||
// if(!this.uploader.isHTML5) this.destroy();
|
||||
|
||||
this.uploader.addToQueue(files, options, filters);
|
||||
if (this.isEmptyAfterSelection()) {
|
||||
// todo
|
||||
this.element.nativeElement.value = '';
|
||||
/*this.element.nativeElement
|
||||
.replaceWith(this.element = this.element.nativeElement.clone(true)); // IE fix*/
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user