Here's my class:
export class Patient {
constructor(public id: number, public name: string, public location: string, public bedId: number, public severity: string,
public trajectory: number, public vitalSigns: [GraphData[]], public latestReading: GraphData[]){
}
public get getCombinedVSData(): Array<GraphData>{
let combinedVitalSigns: GraphData[] = [];
for (let data of this.vitalSigns){
combinedVitalSigns.push(data[0]);
}
return combinedVitalSigns;
}
}
When I print one of my patients,
console.log(this.patientService.patients[0]);
I get this:
In my application, I need to convert the patient to JSON to move it with drag and drop:
let thisIsNotFine=JSON.stringify(this.patientService.patients[0]);
Here comes the problem. When I convert it back to a JS object and print it,
console.log(JSON.parse(thisIsNotFine));
I get this:
As you can see, it is no longer called a Patient
in the console, and the getCombinedVSData
getter is gone.
Is this normal behaviour? How can I keep the getter on the object when converting it to JSON? Thank you.