Working on angular4 for a while, today I came to a scenario where my service is returning me a map instead of a JSON response. How can I map that service with my map. Error I am getting in visual studio Type Info cannot be assigned to type Map<string, Info>. My code is as below: Please advice me did I make a correct model class? how to map service map response to my map.
response from service
{
"1":{
"id":"1",
"name":"Anna"
},
"2":{
"id":"2",
"name":"Martin"
}
}
ts file
myMap: Map<string, Info>;
this.groupService.fetchInfo().subscribe(data => {
this.myMap= data; // Error in visual studio: Type Info cannot be
// assigned to type Map<string, Info>
});
Info model
// Not sure if this model structure is correct
export interface Info{
id: string;
name: string;
}
service
fetchInfo(): Observable<Info>{
const url = "/info/getInfo";
return this.httpClient.get<Info>(url);
}
<Info>to<Map>?