Why is it necessary to convert event.body
into a JSON string and then parse it back into an object?
this.excelFileService.upload(this.currentFileUpload).subscribe(event => {
if (event.type === HttpEventType.UploadProgress) {
this.progress.percentage = Math.round(100 * event.loaded / event.total);
} else if (event instanceof HttpResponse) {
let excelFile: ExcelFile = JSON.parse(JSON.stringify(event.body));
this.excelFiles.push(excelFile);
}
});
If I simply pass event.body
directly to push
, it results in a compilation error:
ERROR in src/app/excel-file/excel-file.component.ts(54,30): error TS2345: Argument of type '{}' is not assignable to parameter of type 'ExcelFile'.
Type '{}' is missing the following properties from type 'ExcelFile': filename, path, createdAt
When I try passing event.body[0]
, it compiles but ends up being an empty object {}
.