1

I have an angular2 component that let user upload a file. This is how i read files when uploaded: template:

<div>
  Select file:
  <input type="file" (change)="changeListener($event)" >
</div>

And changeListener code portion for read file:

 var reader:FileReader = new FileReader();
 reader.onloadend = function(e){
    console.log(reader.result);
 }
 reader.readAsText(event.target.files[0], 'ISO-8859-1');

In this way i'm able to read entire file, but i need to read line by line. How can i do ?

Claies
  • 22,124
  • 4
  • 53
  • 77
giozh
  • 9,868
  • 30
  • 102
  • 183
  • Do you need to push each line to an array? – Stubbies Apr 03 '17 at 14:06
  • 1
    `result.split("\n")` will give you an array that you can loop each line. [Possible duplicate.](http://stackoverflow.com/questions/23331546/how-to-use-javascript-to-read-local-text-file-and-read-line-by-line) – Stubbies Apr 03 '17 at 14:09

0 Answers0