I am currently working with Angular5 within a spring boot application and I am attempting to retrieve a Map object in JSON format.
Spring :
//sample method
return ResponseEntity.ok((new Gson()).toJson(/*My map object*/));
Angular5 :
sql_list = new Map<string,string>();
this.myService.getQueries().subscribe(
data => {
console.log("Data Received: ");
console.log(data);
this.sql_list = data;
console.log(this.sql_list.get("query1"));
}
);
When inspecting the client side, I can confirm data reception using console.log:
Data Received:
{
"query1" : "select * from test",
"query2" : "select * from test2",
"query3" : "select * from test3"
}
However, when attempting to utilize the map.get(string key)
method on the sql_list
object, it results in the following error:
ERROR TypeError: _this.sql_list.get is not a function
What error have I made here?
EDIT: Upon following Florian's suggestion, the issue was resolved:
this.sql_list = new Map<string, string>(Object.entries(data));