Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何从输入文件中删除重复文件(角度)_Angular_File_File Upload - Fatal编程技术网

Angular 如何从输入文件中删除重复文件(角度)

Angular 如何从输入文件中删除重复文件(角度),angular,file,file-upload,Angular,File,File Upload,我正在做一个webApp,它有一个页面可以上传一些文件,每个文件有一个不同的输入文件,我可以从中向文件数组添加文件,问题是如果用户从同一个输入文件中选择一个文件两次,同一类型的文件将有两个不同的文件,如果用户已经上传了该输入的第一个文件,我如何删除该输入的第一个文件,我只需要为每个输入上传一个文件 这就是我得到的 在我的模板中: <input type="file" id="file3" (change)="onSelectCartaTra

我正在做一个webApp,它有一个页面可以上传一些文件,每个文件有一个不同的输入文件,我可以从中向文件数组添加文件,问题是如果用户从同一个输入文件中选择一个文件两次,同一类型的文件将有两个不同的文件,如果用户已经上传了该输入的第一个文件,我如何删除该输入的第一个文件,我只需要为每个输入上传一个文件

这就是我得到的

在我的模板中:

<input type="file" id="file3" (change)="onSelectCartaTrabajo($event)" />  
<div fxLayout="row wrap" fxFlex="50" fxLayoutGap="30px">
    <label for="file3">
      <span class="material-icons icon-upload"> upload </span> Seleccionar
      archivo
    </label>
    <span class="fileName" *ngIf="CartaDeTrabajo" fxFlex="50">{{
      CartaDeTrabajo
    }}</span>
  </div>

    <p class="pl-1">
    <fa-icon class="faCaretRight mr-4" [icon]="faCaretRight"></fa-icon
    >Declaración de renta
  </p>
  <input
    type="file"
    id="file2"
    (change)="onDeclaracionDeRentaChange($event)"/>
  <div fxLayout="row wrap" fxFlex="50" fxLayoutGap="30px">
    <label for="file2">
      <span class="material-icons icon-upload"> upload </span> Seleccionar
      archivo
    </label>
    <span class="fileName" *ngIf="declaracionRenta" fxFlex="50">{{
      declaracionRenta
    }}</span>
</div>

您可以清除fileInput的旧值

在onSelectCartaTrabajo方法中

或者,您可以向fileInput添加一个clickEvent,并在每次单击时将该值设置为null,这样您的html将如下所示

<input #fileInput3 type="file" id="file3"(click)="fileInput3.value = null" (change)="onSelectCartaTrabajo($event)" />

这将始终将旧的fileInput3值设置为null,而不是在HTML中,您也可以创建一个方法并在单击时调用它,然后传递$event并将值设置为null`

感谢您的响应,我有一个疑问,何时从数组中删除较旧的文件?event.target.value=null将始终删除fileInput的最后一个值,这样在同一个输入中就不再有2个文件了,只有新选择的文件会在那里。我尝试了在html中将文件的值设置为null的方法,但它给了我一个错误:undefinedIt不起作用,数组中仍然有我以前选择的旧文件。你到底想要什么,我现在很困惑!!
onSelectCartaTrabajo(event: any){
    //do all stuff if valid then do the below
    event.target.value = ''; //or null
}
<input #fileInput3 type="file" id="file3"(click)="fileInput3.value = null" (change)="onSelectCartaTrabajo($event)" />