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?

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. Can I do this in component?
What component? Sorry, I don't understand your question.
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?
Why should it not work ;). Just put the html it in your template or in a template file when you are using a templateUrl.
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 = '';.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.