Typescript/Angular – Create array of objects from json file then get specific item
I’m having difficulty trying to accomplish a task.
I have a json file like this:
[
{
"name" : "blah",
"size" : "medium",
"speed" : 25,
},
{
"name" : "blah",
"subtype" : ["blah", "blah", "blah"],
"size" : "medium",
"speed" : 30,
},
{
"name" : "blah",
"size" : "medium",
"speed" : 30,
}
]
I want to create an array of objects, which I believe I have to do like this:
getObjects() {
return this.http.get(‘/assets/raceInfo.json’);
}
Then I would like to get a specific one something like:
getObject(name: string) { return this.http.get('/assets/raceInfo.json').select(x => x.name === name); }
i’m completely new to typescript and angular, so any help much appreciated.
Source: Angular Questions