I cannot figure out how to map the json object array returned from the web service to a properly typed object array in an Angular 2 application.
As you can see in the official Angular 2 example in plunker, the expected objects are not of type Hero, they are of type Object and hero: Hero [], the member of HeroListComponent is actually Object []. You can see in the console that the array is not strongly typed:
http://plnkr.co/edit/Qa22yzPh3JWI8lNZ99Ik?p=preview
I added an additional call to console.log () to add the hero command, you can see in the browser console that we do not have Hero [], but Object [].
Thus, it is obvious that the conversion does not work:
this.http.get(this._heroesUrl)
.map(res => <Hero[]> res.json().data)
.catch(this.handleError);
and instead of Object [] we get Object [].
, json ?
:
https://angular.io/docs/ts/latest/guide/server-communication.html