I have successfully created a FileReader() instance and can read the text files on file change. But what I need is; without using the input button to select a file, all I have to do is to place the path in an input textbox and read its contents. Please see my code below.
.ts file
fileChanged(e: any) {
this.file = e.target.files[0];
this.readDocument();
}
readDocument() {
const fileReader = new FileReader();
fileReader.onload = (e) => {
console.log(fileReader.result);
}
fileReader.readAsText(this.file);
}
.html
<div class="Block">
<label id="lbl">Code </label>
<input type='file' (change)="fileChanged($event)">
</div>
If fileReader is not a viable option, can you please show me how to do this using another way? Thank you.