'Angular: How to store FileReader content in a variable or an array
I'm so confused about this but is there a way to store FileReader content into a variable or an array as it is, because I need that content into another component.
This is my code snippet:
fileChangeListener($event: any): void {
this.fileSize = Math.round($event.target.files[0].size /1024) + 'KB';
this.fileName = $event.target.files[0].name;
this.fileType = $event.target.files[0].type;
this.filelastModifiedDate = new Date($event.target.files[0].lastModified).toLocaleDateString();
console.log(this.fileName, this.fileType);
console.log('submitted here');
const file = $event.target.files[0];
const fileReader = new FileReader();
fileReader.onload = (e) => {
const data = fileReader.result;
this.storeResults(data);
this._fileReader = data;
// console.log('FileREAAAAAAAAAAADER \n', data);
console.log(this._fileReader);
this.parseData(data);
};
return fileReader.readAsText(file);
}
component.html:
<mat-form-field (change)="fileChangeListener($event)">
<ngx-mat-file-input formControlName="multiplefile" placeholder="Multiple inputs" multiple></ngx-mat-file-input>
<mat-icon matSuffix>folder</mat-icon>
</mat-form-field>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|