In this code snippet, I am creating an input element with the file type without adding it to the DOM. My goal is to retrieve the value of this input once the user selects a file. Even though the input is not part of the HTML template, I still want to access its value.
<p-splitButton
label="Add document"
icon="pi pi-plus"
(onClick)="openAddDocument()"
[model]="addDocumentButtonMenuItems"
styleClass="p-button-help"
></p-splitButton>
public readonly addDocumentButtonMenuItems = [
{
label: 'Download document', icon: 'pi pi-upload', command: () => {
this.uploadFile();
},
},
];
public uploadFile(): void {
const input = document.createElement('input');
input.type = 'file';
input.click();
}
Is there a way to get the value from this input element?