I have a TypeScript class that looks like this -
export class News {
title: string;
snapshot: string;
headerImage: string;
}
In my Angular service, I have a method that retrieves a list of news in the following way -
private searchNews(sortOrder : string, query? : string):Observable<News[]>{
return this.http.get(this.url+'?'+this.buildParams(sortOrder,10,0,query))
.map((res:Response) => res.json())
.catch((error:any) => Observable.throw(error.json().error || 'Server error'))
}
Here is an example of the JSON data I'm receiving from the server -
[{
"jcr:path":"someurl",
"title":"Hello News",
"snapshot":"Here is a snapshot",
"headerImage":"image.png"
},
...
]
Now, I want to add a field "path" in my News class which will map the value of the "jcr:path" field in the JSON data.
However, I can't simply write the class like this -
export class News {
jcr:path:string;// I may write it as - path:string
title: string;
snapshot: string;
headerImage: string;
}
Is there a way in TypeScript where I can instruct it to extract the value of the "path" field from the "jcr:path" properties?