0

I am using html file upload.

<input type="file" name="filedata" class="form-control" #file/>

After selection of file, file name showing in screen/UI.

<button pButton type="button" icon="fa-check" class="form-control" 
(click)="uploadFileByRest();" label="Upload"></button>

I am using upload button for uploading that file to Alfresco. On clicking on upload button I need to empty the file selected. Need to change file name showing to "No file chosen", which is showing before selecting file. How to do this?

Veera
  • 357
  • 4
  • 18

1 Answers1

1

Setting the value to an empty string should do that according to how to reset <input type = "file">

<button pButton type="button" icon="fa-check" class="form-control" 
    (click)="uploadFileByRest();file.value = ''" 
    [disabled]="!isFileSelected" label="Upload"></button>
Günter Zöchbauer
  • 490,478
  • 163
  • 1,733
  • 1,404
  • Thanks. Can I do this in component? – Veera Jul 07 '17 at 06:51
  • What component? Sorry, I don't understand your question. – Günter Zöchbauer Jul 07 '17 at 06:54
  • Angular2 component I am asking. You told fix in html. Good. I am coding in Angular 2. Can I do that value = '' in angular component? – Veera Jul 07 '17 at 07:09
  • Why should it not work ;). Just put the html it in your template or in a template file when you are using a templateUrl. – Akkusativobjekt Jul 07 '17 at 07:17
  • 1
    You mean it TypeScript code. The HTML template of a component is part of the component, this was confusing me. You can do it in code as well. You need a reference to `#file`. You can do it by passing it in `(click)="uploadFileByRest(file)"` and then in `uploadFileByRest(file) { ...; file.value = ''; }`, or using `@ViewChild('file') file:ElementRef,` and then in code `this.file.nativeElement.value = '';`. – Günter Zöchbauer Jul 07 '17 at 07:18