title: Angular 2 - good practice during conversion response into angular model
body: <p>What is a good practice for conversion response (for e.g. json data) into angular model ? So, in other words how to achieve Auto Mapper functionality in angular 2.</p>
  
  <p><strong>team.service.ts</strong></p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { Http, Response } from '@angular/http';
  import 'rxjs/add/operator/toPromise';
  import { Team } from './team.model';
  
  @Injectable()
  export class TeamService {
  
    constructor(private _http: Http) {
    }
  
    public GetAllTeams(): Promise&lt;Team[]&gt; {
      return this._http.get('/app/teams/shared/team.data.json')
                      .toPromise()
                      .then(respons =&gt; &lt;Team[]&gt; respons.json().data as Team[])
                      .then(data =&gt; { return data; });
    }
  }
  </code></pre>
  
  <p><strong>team.data.json</strong></p>
  
  <pre><code>{
      "data": [
          {"id": "1", "name": "Team 1", "otherProperty" : "S1"},
          {"id": "2", "name": "Team 2", "otherProperty" : "S2"},      
      ]
  }
  </code></pre>
  
  <p><strong>team.model.ts</strong></p>
  
  <pre><code>export class Team {
  
    private _id: string;
    public get id(): string {
      return this._id;
    }
  
    public set id(value: string) {
      this._id = value;
    }
  
    private _name: string;
    public get name(): string {
      return this._name;
    }
  
    public set name(value: string) {
      this._name = value;
    }
  
    private _icon: string;
    public get icon(): string {
      return this._icon;
    }
  
    public set icon(value: string) {
      this._icon = value;
    }
  
  }
  </code></pre>
  
  <p>Method <code>GetAllTeams</code> should returns <code>Team</code> objects. I am aware that I can create factory which receive json data and return Array of Team objects, but after reading this article <a href="https://angular.io/docs/ts/latest/guide/dependency-injection.html" rel="nofollow noreferrer">https://angular.io/docs/ts/latest/guide/dependency-injection.html</a> (section car-factory.ts), it seems that it is bad pattern.
  Thanks.</p>