重置具有输入标签文件类型的文件,动态类型为angular 6

时间:2019-01-25 09:25:05

标签: angular file-upload angular6 dynamicform

如果文件不受支持,则我想重置所选文件的类型格式 demo,但其他具有支持格式的输入标签文件也使用动态格式即时重置

kyc.component.ts

  handleFileInput(files: FileList, label: string): void {
    this.fileToUpload = files.item(0);
    if ((this.fileToUpload.type === 'image/bmp' && this.fileToUpload.size <= 10000000) 
    || (this.fileToUpload.type === 'application/pdf'&& this.fileToUpload.size <= 10000000) 
    || (this.fileToUpload.type === 'image/gif'&& this.fileToUpload.size <= 10000000)
    || (this.fileToUpload.type === 'image/jpeg'&& this.fileToUpload.size <= 10000000) 
    || (this.fileToUpload.type === 'image/png'&& this.fileToUpload.size <= 10000000) 
    || (this.fileToUpload.type === 'application/msword'&& this.fileToUpload.size <= 10000000)
    || (this.fileToUpload.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'&& this.fileToUpload.size <= 10000000)) {
        this.uploadFile(this.settingService.uploadFile(), this.fileToUpload, label);
    } else {
        this.data[label] ="";
        this.notiService.printErrorMessage(MessageContstants.CHECK_FILE);
    }            
}

kyc.component.html

<input *ngIf="field.type.name == fieldTypeNames.File" class="full-width" (change)="handleFileInput($event.target.files, field.label)" [(ngModel)]="data[field.label]" name="field.label" type="File" placeholder="{{field.description}}"accept=".jpeg, .jpg, .gif, .png, .bmp, .docx, .doc, .pdf,"  required />

我也尝试了另一种解决方法,例如https://stackoverflow.com/a/40165524/9970857,但也没有奏效,需要建议和意见,在这个问题上停留了一周,

0 个答案:

没有答案