I have this code in Angular
import { Component } from '@angular/core';
import {NgForm} from "@angular/forms";
@Component({
selector: 'app-add-route',
templateUrl: './add-route.component.html',
styleUrls: ['./add-route.component.scss']
})
export class AddRouteComponent {
public fileContent: string;
constructor() { }
onSubmit(form: NgForm) {
}
getFile(event) {
let file = event.target.files[0];
let filename = file.name;
let result;
if((filename.split('.').pop()) === 'gpx') {
let reader = new FileReader();
reader.readAsText(file);
this.fileContent = // what should be here?
}
}
}
I would like to access the file from input file from the form (which must be type of .gpx), get the content (using FileReader()). How can I store filecontent once upon its loaded into class variable fileContent?