Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
186
rated 0 times [  192] [ 6]  / answers: 1 / hits: 21045  / 8 Years ago, sat, march 5, 2016, 12:00:00

I am very new to angularjs. I wasn't able to find the solution online.
I would like to read the text from a file. I was trying to follow this example.
FileReader not loading file properly using AngularJS



However, since I'm using TypeScript, I receive this error for this line



document.getElementById('fileInput').files[0];


Error:
Property 'files' does not exist on type 'HTMLElement'.



Please suggest me how I can cast to use the files.


More From » html

 Answers
106

This should work fine from that example, maybe you're doing something wrong there. However, you may test your code like this, replace fileChanged() by fileChanged(event) and then get the files by event.target.files





function fileChanged(event) {
var target = event.target || event.srcElement;
console.log(target.files);
console.log(document.getElementById('fileInput').files);
}

<div>
<input ng-model=csv
onchange=fileChanged(event)
type=file id=fileInput/>
</div>




[#63039] Thursday, March 3, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
trinityr

Total Points: 49
Total Questions: 107
Total Answers: 96

Location: Mayotte
Member since Fri, Oct 1, 2021
3 Years ago
;