I have 2 Interfaces:
DTO.ts
export interface Report{
berichtId: number,
summary: Label
}
export interface Label{
text: string
}
I use them to type my HttpClient get request, to receive an array of Reports:
Dao.service.ts
getReports():Observable<DTO.Report[]>{
return this.http.get<DTO.Report[]>(Dao.API+'report/current')
.pipe(
retry(3),
catchError(this.handleErrors)
);
What I get is this JSON:
[
{
"berichtId":1777,
"summary":
"{\"text\":\"asdf\"}"
}
]
Now I want to read them out but these slashes dont let me convert the JSON to my pre defined interface Report object. It just translates it to a normal string.
this.dao.getReports().subscribe(report=>{
console.log(report[0].summary); // {"text":"asdf"}
console.log(report[0].summary.text) // undefined
});
What is the best way to handle that problem? There are solutions online but they are often rather counter intuitive. There must be a better way in Angular.