I have a API returning following data:
[
{
"id": 1,
"symbol": "20MICRONS",
"series": "EQ",
"isin": "INE144J01027",
"created_at": "2018-03-05 16:24:10",
"updated_at": "2018-03-05 16:24:10"
},
{
"id": 2,
"symbol": "3IINFOTECH",
"series": "EQ",
"isin": "INE748C01020",
"created_at": "2018-03-05 16:24:10",
"updated_at": "2018-03-05 16:24:10"
},
{
"id": 3,
"symbol": "63MOONS",
"series": "EQ",
"isin": "INE111B01023",
"created_at": "2018-03-05 16:24:10",
"updated_at": "2018-03-05 16:24:10"
},
{
"id": 4,
"symbol": "VARDMNPOLY",
"series": "EQ",
"isin": "INE835A01011",
"created_at": "2018-03-05 16:24:10",
"updated_at": "2018-03-05 16:24:10"
}
]
I wish to parse this response from api in angular. I am able to log the data in console but not able to map in the datatype.
export class SymbolsComponent implements OnInit {
allSymbols: Symbols[] = [];
constructor(private http: HttpClient, private apiUrl: ApiUrlService) { }
ngOnInit() {
this.fetchListOfAllSymbol();
}
fetchListOfAllSymbol() {
this.http.get(this.apiUrl.getBaseUrl() + 'symbol').subscribe(data => {
console.log(data);
});
}
}
My model file looks like this:
export class Symbols {
constructor(private symbol: string, private series: string, private isin: string, private created: string) {
}
}
After getting response from the API i need to populate the result in allSymbols variable.
this.http.get(this.apiUrl.getBaseUrl() + 'symbol').map(response => response.json()).subscribe(data => { console.log(data);});response.json is not a function