title: How to cast object in object into Angular Class (Type)
body: <p>How can I cast <code>obj.category</code> into <code>Category</code> type in example below?</p>
  
  <p>I need this to set selected options in dropdown.</p>
  
  <pre><code>export class Category{
      id: number;
      name: string;
  
      constructor(obj: any) {
          this.id = obj.id;
          this.name = obj.name;
      }
  }
  
  
  export class Post {
      category: Category[];
  
      constructor(obj: any) {
          this.category = obj.category;
      }
  }
  </code></pre>
  
  <p>Category service looks like this:</p>
  
  <pre><code>getCategories(): Promise&lt;Category[]&gt; {
      return this.http.get(this.appConfig.apiEndpoint + 'categories/').toPromise()
    .then(response =&gt; response.json().map(obj =&gt; new Category(obj)))
    .catch(this.handleError);
  }
  </code></pre>
  
  <p>Api response: </p>
  
  <pre><code>[{"id":1,"name":"cat1"},{"id":2,"name":"cat2"}]
  </code></pre>
  
  <p>Template:</p>
  
  <pre><code>&lt;select multiple name="category" [(ngModel)]="obj.post.category"&gt;
      &lt;option  *ngFor="let category of categories" [ngValue] = "category"&gt;
         {{category.name}}
      &lt;/option&gt;
  &lt;/select&gt;
  </code></pre>