I wish to create an upload function for my Apps by using IONIC.
Here is my HTML code:
<input ion-button block type="file" id="uploadBR">
<input ion-button block type="file" id="uploadIC">
<button ion-button block (click)="upload()">Confirm Claim Restaurant</button>
Here is my upload()
function:
upload(){
let BR = document.getElementById('uploadBR').files[0]
let IC = document.getElementById('uploadIC').files[0]
console.log(BR)
console.log(IC)
}
In normal HTML it should work, but it doesn't work with my IONIC.
When building the App, it will show the error Typescript Error: Property 'files' does not exist on type 'HTMLElement'.
Am i do it in wrong way or it has to be done in different way with typescript?
Thanks.
The error "Property 'X' does not exist on type 'HTMLElement'" occurs when we try to access a property that doesn't exist on an element of type HTMLElement . To solve the error, use a type assertion to type the element correctly before accessing the property. This is the index.
The HTMLInputElement interface provides special properties and methods for manipulating the options, layout, and presentation of <input> elements.
You neet to cast it as a HTMLInputElement as files
is a property of input
element
let BR = (<HTMLInputElement>document.getElementById('uploadBR')).files[0];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With