I am working on learning Angular 2 and Typescript. I am building a simple web application that grabs data from a WEB API and displays it in a list. Then once the user clicks an item in the list, they are taken to a details page.
I have a service that I created to make the API call that does the following:
GetData() {
let data = this.http.get('http://server.name/api/GetData')
.map((res) => res.json());
return data;
}
Then in a component, I subscribe to the data like this:
this.myService.GetData()
.subscribe((myService) => this.items = myService);
When the http.get returns, I would like to do some processing on the JSON objects before I return from the GetData() method. For example, add a new property called ID. Essentially something like the pseudo code below:
for each(item in data) {
item.ID = newID(); //method for creating IDs
}
- Is this something that can be done?
- If yes, is it something that SHOULD be done, or is there a better way to accomplish what I am trying to do?
Thanks
angularjs. There's already onemap, what does stop you from adding an another one? The operator exists exactly for that.